String filepath=request.getParameter("t1c25"); 获取一个JSP页面的file控件的路径。
其中 filepath是C:\Documents and Settings\lwl\×ÀÃæ\1.jpg 其实是桌面上的1.jpg 但获取出来的是英文File file=new File(filepath);//报错说找不到系统文件在网上找到说这样
File file=new File(URLDecoder.decode(filepath));
但也不行 还是报一样的错.
请问要怎么解决..
其中 filepath是C:\Documents and Settings\lwl\×ÀÃæ\1.jpg 其实是桌面上的1.jpg 但获取出来的是英文File file=new File(filepath);//报错说找不到系统文件在网上找到说这样
File file=new File(URLDecoder.decode(filepath));
但也不行 还是报一样的错.
请问要怎么解决..
File file=new File(URLDecoder.decode(filepath,"gbk"));
这2个都不行,错误还是一样。
C:\Documents and Settings\lwl\×ÀÃæ\1.jpg (系统找不到指定的路径。)
public static void main(String[] args) {
String path = "C:/Documents and Settings/Administrator/桌面/1.txt";
File file = new File(path);
System.out.println(file.length());
}
我试了没问题,UTF-8的工程
或者页面采用post提交,并指定编码格式,servlet里面request.setCharacterEncoding成与页面同样的编码。再去getparameter
我试过我的能行
String s = "C:\\Documents and Settings\\admin\\桌面\\1.JPG";
File f=new File(s);
System.out.println(f.exists());
<form action="Test" method="post">
<input name="pic" value="C:\Documents and Settings\admin\桌面\heh.JPG" />
<input type="submit" />
</form>servlet中
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
File file = new File(request.getParameter("pic").replace("\\", "\\\\"));
System.out.println(file.isFile());我是通过测试的
如果还是有问题 就看看字符集编码要统一