网络流写入文件中

/**
* Save XML to local

* @throws Exception
*/
protected void saveDataSourceFile(String fileName, String urlAddress)
throws Exception {
// DNS setting
// java.security.Security.setProperty("networkaddress.cache.negative.ttl", "0");
// java.security.Security.setProperty("networkaddress.cache.ttl", "0");
// System.setProperty("sun.net.inetaddr.ttl", "0");
// System.setProperty("sun.net.inetaddr.negative.ttl", "0");
int byteLength = 0;
byte[] input_buffer = new byte[BUF_SIZE];
BufferedOutputStream outStream = null;
InputStream inStream = null;
try {
outStream = new BufferedOutputStream(new FileOutputStream("Mark.txt"), BUF_SIZE);
URLConnection urlCon = null;
URL url = new URL(locationUrl);
urlCon = url.openConnection();
urlCon.setConnectTimeout((int) 100000);
urlCon.setReadTimeout((int) 100000);
inStream = urlCon.getInputStream();
while ((byteLength = inStream.read(input_buffer, 0, BUF_SIZE)) > 0) {
outStream.write(input_buffer, 0, byteLength);
}
// Close streams.
outStream.flush();
} finally {
if (outStream != null) {
outStream.close();
}
if (inStream != null) {
inStream.close();
}
}
}

你可能感兴趣的:(exception,String,网络,buffer,input,byte)