java!!环境在linux里面:FileInputStream读取文件的时候http://变成http:/丢掉了一个斜杠

long2330 2010-12-01 12:35:14
代码如下:
debuglog.debug("filePath " + filePath);
BufferedInputStream in = new BufferedInputStream(new FileInputStream(
filePath));

日志打出来:
http://xxx.xxx.xxx.xxx:80/02100490113004/WallpaperImg/caitiao_360x640.jpg
这里很明显http://这两个斜杠都还存在

但是一走到下面读取这个文件的时候就报错了
java.io.FileNotFoundException: http:/xxx.xxx.xxx.xxx:80/02100490113004/WallpaperImg/caitiao_360x640.jpg (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at com.huawei.wallpaper.action.WallPaperAction.fileToByteArray(WallPaperAction.java:176)
at com.huawei.wallpaper.action.WallPaperAction.sendMMS(WallPaperAction.java:120)
这个报错的原因就是因为少了一个斜杠,所以就报找不到文件,我很无语
如果说这个读取的时候自动把双斜杠转换成单斜杠,那我就没办法了,因为我也测试过相对路径,也无法获取到。


...全文
1849 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
幽饮烛 2011-02-10
  • 打赏
  • 举报
回复
!!!??
文件流是无法打开网络上的文件的。

你可以使用

URL url = new URL("http://xxxxxx");

BufferedInputStream in = new BufferedInputStream(url.openStream());
nisuifen 2010-12-02
  • 打赏
  • 举报
回复
8楼的 好像可以吧。
saintjetsu 2010-12-02
  • 打赏
  • 举报
回复
URLConnection urlConnection = url.openConnection()
BufferedInputStream in = new BufferedInputStream(urlConnection.getInputStream())

可以参考下~
Jlins 2010-12-01
  • 打赏
  • 举报
回复
使用 "url:http://xxx.xxx.xxx.xxx:80/02100490113004/WallpaperImg/caitiao_360x640.jpg"
试试?
shybirdshy 2010-12-01
  • 打赏
  • 举报
回复
他把双斜杠单成单斜杠 那LZ加2个斜杠上去不就行了么
long2330 2010-12-01
  • 打赏
  • 举报
回复
没有高手遇到过类型的问题???
自己顶了
期待高手降临
long2330 2010-12-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dyllove98 的回复:]
url: 是网络地址通配符.
使用URL url = new URL("url:http://xxx.xxx.xxx.xxx:80/02100490113004/WallpaperImg/caitiao_360x640.jpg")

或者
file file = new file( "url:http://xxx.xxx.xxx.xxx:80/02100490113004/Wallpa……
[/Quote]

测试过了 没有用 还是少一个斜杠。
不过还是谢谢你
long2330 2010-12-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dyllove98 的回复:]
url: 是网络地址通配符.
使用URL url = new URL("url:http://xxx.xxx.xxx.xxx:80/02100490113004/WallpaperImg/caitiao_360x640.jpg")

或者
file file = new file( "url:http://xxx.xxx.xxx.xxx:80/02100490113004/Wallpa……
[/Quote]

我的new FileInputStream(
filePath)里面只能放一个String,我就将这个字符串拼接上uel:然后扔进去就行了?
Jlins 2010-12-01
  • 打赏
  • 举报
回复
url: 是网络地址通配符.
使用URL url = new URL("url:http://xxx.xxx.xxx.xxx:80/02100490113004/WallpaperImg/caitiao_360x640.jpg")

或者
file file = new file( "url:http://xxx.xxx.xxx.xxx:80/02100490113004/WallpaperImg/caitiao_360x640.jpg");


[Quote=引用 2 楼 long2330 的回复:]

引用 1 楼 dyllove98 的回复:
使用 "url:http://xxx.xxx.xxx.xxx:80/02100490113004/WallpaperImg/caitiao_360x640.jpg"
试试?

加个url就行了?那怎么能取得到了?
[/Quote]
long2330 2010-12-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dyllove98 的回复:]
使用 "url:http://xxx.xxx.xxx.xxx:80/02100490113004/WallpaperImg/caitiao_360x640.jpg"
试试?
[/Quote]
加个url就行了?那怎么能取得到了?

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧