Get files over HTTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (i = 0; i < _numFiles; i++) { | |
try { | |
//get the next file name | |
fileName = _fileList[i].substring(_fileList[i].lastIndexOf("/")+1); | |
//associate file (URL) with the httpMethod | |
HttpMethod getXMLFile = new GetMethod( | |
_fileList[i]); | |
//go get the file | |
_filehttp.executeMethod(getXMLFile ); | |
//header info is useful (modified d/ts & size) - | |
//i check it in my code to init downstream processing - this just grabs it | |
Header[] respHeader = getXMLFile.getResponseHeaders(); | |
//gotta have something to write to | |
InputStream inFileStream = getXMLFile.getResponseBodyAsStream(); | |
//_xmldest is a config-file set directory read upstream to this | |
File outFile = new File(_xmldest + fileName); | |
//create file | |
FileOutputStream outFileStream = new FileOutputStream(outFile); | |
//set buffer size | |
byte[] buffer = new byte[1024]; | |
k = 0; | |
//write to file | |
while ((k = inFileStream.read(buffer)) > 0 ) { | |
outFileStream.write(buffer,0,k); | |
} | |
//remember to close! | |
inFileStream.close(); | |
outFileStream.close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
error++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment