解决java java.io.FileNotFoundException: http:\localhost:8080 (文件名、目录名或卷)问题
2016-01-26 13:25
2006 查看
转载自:http://blog.csdn.net/zelda002/article/details/7601653
解决java java.io.FileNotFoundException: http:\localhost:8080 (文件名、目录名或卷)
http中双斜杠变单斜杠的问题
File file = new File("http://127.0.0.1:8080/weibo.properties");
InputStream in = null;
try {
System.out.println("以字节为单位读取文件内容,一次读一个字节:");
// 一次读一个字节
in = new FileInputStream(file);
int tempbyte;
while ((tempbyte = in.read()) != -1) {
out.write(tempbyte);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
return;
}
以上读取方式会报此错。
以上功能实现改为:
URL url = new URL("http://127.0.0.1:8080/weibo.properties");
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn
.getInputStream()));
String line = null;
try {
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} finally {
reader.close();
}
解决java java.io.FileNotFoundException: http:\localhost:8080 (文件名、目录名或卷)
http中双斜杠变单斜杠的问题
File file = new File("http://127.0.0.1:8080/weibo.properties");
InputStream in = null;
try {
System.out.println("以字节为单位读取文件内容,一次读一个字节:");
// 一次读一个字节
in = new FileInputStream(file);
int tempbyte;
while ((tempbyte = in.read()) != -1) {
out.write(tempbyte);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
return;
}
以上读取方式会报此错。
以上功能实现改为:
URL url = new URL("http://127.0.0.1:8080/weibo.properties");
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn
.getInputStream()));
String line = null;
try {
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} finally {
reader.close();
}
相关文章推荐
- 盛大离场:游戏到泛娱乐的鸿沟有多远?(上)
- AFNetworking判断网络状态
- Http请求
- BP神经网络的Python实现
- linux网络命令(十)之tsar
- 网络协议:TCP/IP、UDP、Http、Socket
- android textView 加载HTML 异步加载网络图片
- Android 网络请求详解
- amfe手机淘宝前端团队 https://github.com/amfe
- 深度神经网络为何很难训练
- HTTP 方法
- http协议详解
- 理解LSTM网络
- http2相关的主要实现,在下不才先走一步
- IHttpModule与IHttpHandler的区别和http请求处理过程,ihttpmodule,ihttphandler 处理流程
- 深度学习与自然语言处理之四:卷积神经网络模型(CNN)
- TCP的三次握手和四次挥手详解
- IHttpModule和IHttpHandler 应用笔记
- HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容
- TCP为什么是四次挥手