Save XML data source

来源:互联网 发布:王江民38岁开始学编程 编辑:程序博客网 时间:2024/06/06 17:11
protected void saveDataSourceFile()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;int BUF_SIZE = 1024;byte[] input_buffer = new byte[BUF_SIZE];BufferedOutputStream outStream = null;InputStream inStream = null;try {outStream = new BufferedOutputStream(new FileOutputStream("DEN.xml"), BUF_SIZE);URLConnection urlCon = null;URL url = new URL(urlAddress);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();}}}