网络流写入文件中
来源:互联网 发布:linux开机自检 编辑:程序博客网 时间:2024/05/10 00:53
/**
* 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();
}
}
}
* 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();
}
}
}
- 网络流写入文件中
- 文件下载(web),把文件写入response流中
- 用java从网络上抓取HTML文件内容并写入本地文本中
- 用java从网络上抓取HTML文件内容并写入本地文本中
- 关于Android在网络上下载文件以及向SD卡中写入文件
- 通过JPcap捕获网络TCP数据包,并将解析的信息写入execl文件中
- activity 中写入布局文件
- java写入TXT文件中
- 写入内容到文件中
- java写入TXT文件中
- 向数据库中写入文件
- 将流写入文件
- 文件写入字节流
- IO流-ObjectOutputStream-将对象写入到文件中
- java中遍历对象流写入的文件
- 学习笔记 - FileOutputStream流将字符串写入文件中
- Java中IO流文件读取、写入和复制
- TC中打开文件和写入文件
- 打开一个新窗口
- wordpress用户权限
- split
- 耳机
- netconsole配置 .
- 网络流写入文件中
- SQL语句
- JSTL和EL的使用
- BackTrack中文指南V9
- STC89C52实现时钟功能
- SVN清除本地已有的用户名和密码
- 如何编制RPG游戏(上)
- Json简介
- 如何编制RPG游戏(下)