public void scfile() throws IOException{
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
//上传文件路径
String fileName = request.getParameter("fielname");
System.out.println("filename=="+fileName);//ceshi.html
InputStream is = null;
FileOutputStream fs = null; DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
try {
//is = cform.getImportfile().getInputStream();
//创建文件
File inFile = new File(fileName);
is=new FileInputStream(inFile);
System.out.println("====");
BufferedReader br=new BufferedReader(new InputStreamReader(is));上面代码有什么问题,哪里错了
红色那行报文件路径[ERROR] ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'fielname' on 'class com.asideal.struts.hyym.action.HyymAction: Error setting expression 'fielname' with value '[Ljava.lang.String;@ae0ba7'
filename==ceshi.html
java.io.FileNotFoundException: ceshi.html (系统找不到指定的文件。)
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
//上传文件路径
String fileName = request.getParameter("fielname");
System.out.println("filename=="+fileName);//ceshi.html
InputStream is = null;
FileOutputStream fs = null; DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
try {
//is = cform.getImportfile().getInputStream();
//创建文件
File inFile = new File(fileName);
is=new FileInputStream(inFile);
System.out.println("====");
BufferedReader br=new BufferedReader(new InputStreamReader(is));上面代码有什么问题,哪里错了
红色那行报文件路径[ERROR] ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'fielname' on 'class com.asideal.struts.hyym.action.HyymAction: Error setting expression 'fielname' with value '[Ljava.lang.String;@ae0ba7'
filename==ceshi.html
java.io.FileNotFoundException: ceshi.html (系统找不到指定的文件。)
inFile = new File(fileName);
}
String fileName = request.getParameter("fielname");这个是文件路径还是文件名字???
你这样的实现方式就不对。哪有这样获取文件名的?
在不同os,不同浏览器,表单中,上传框的文本内容,通过request.getParameter("");获取的内容都不尽一样,有的是带路径的,有的却不是。所以,只能是,通过上传组件(你所使用的上传第三方jar),获取上传对象,从中获取文件名,size,类型等等信息。
FileInputStream fin = null;
FileOutputStream fout = null;
.....
fout = new FileOutputStream(new File(filename));