public void copyFile(String fromPath, String toPath) {
try {
int bytesum = 0;
int byteread = 0;
File oldfile = new File(fromPath); if (oldfile.exists()) { InputStream inStream = new FileInputStream(fromPath);
FileOutputStream fs = new FileOutputStream(toPath);//这句报错,说toPath拒绝访问,为啥?
byte[] buffer = new byte[1444]; while ((byteread = inStream.read(buffer)) != -1) {
bytesum += byteread;
System.out.println(bytesum);
fs.write(buffer, 0, byteread);
} inStream.close();
fs.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
顺便说一下,toPath是File生成的文件夹,所在路径是
D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\PPP\pqal
public static void createFolder(String folderPath) {
try {
File fp = new File(folderPath); if (!fp.isDirectory()) {
fp.mkdirs();
}
} catch (Exception e) {
e.printStackTrace();
}
}
我看了一下toPath,发现属性是只读的,可是我把只读的勾去掉,过一会再看,还是只读的!高手看看,是我生成文件夹的方式不对,还是不应该生成在eclipse的workspace里???
try {
int bytesum = 0;
int byteread = 0;
File oldfile = new File(fromPath); if (oldfile.exists()) { InputStream inStream = new FileInputStream(fromPath);
FileOutputStream fs = new FileOutputStream(toPath);//这句报错,说toPath拒绝访问,为啥?
byte[] buffer = new byte[1444]; while ((byteread = inStream.read(buffer)) != -1) {
bytesum += byteread;
System.out.println(bytesum);
fs.write(buffer, 0, byteread);
} inStream.close();
fs.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
顺便说一下,toPath是File生成的文件夹,所在路径是
D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\PPP\pqal
public static void createFolder(String folderPath) {
try {
File fp = new File(folderPath); if (!fp.isDirectory()) {
fp.mkdirs();
}
} catch (Exception e) {
e.printStackTrace();
}
}
我看了一下toPath,发现属性是只读的,可是我把只读的勾去掉,过一会再看,还是只读的!高手看看,是我生成文件夹的方式不对,还是不应该生成在eclipse的workspace里???
解决方案 »
- 学生信息无法显示
- Hibernate在<many-to-many>时设置lazy=true的问题
- jfreechart报表显示问题
- 一个使用 AJAX servlet返回EXCEL 问题
- 如何通过action跳转到带有Frame页面的jsp
- 是高手,就请看看这个问题?
- 关于IE浏览器的一个疑问,请进
- 回复评语中插入小图标是如何保存到数据库的?
- 推荐几本关于JSP的书,最好能从网上下到
- 请教,急!!!!
- The server encountered an internal error () that prevented it from fulfilling th
- jstl显示无效,跳不进<c:choose><c:if>等标签
参数你最好配个File类型的。
2.注意一下,好的编程习惯,你应该在finally中把文件流关闭一下。