jsp中如何复制文件 要用到java的“流”,不过那样安全吗?可行性高吗?客户端也 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /** *功能:将一个文件复制粘贴到另一文件夹中,并可改名.路径为文件的绝对路径。 *@param sourcefile 源文件 *@param targetfile 目标文件 *@return true or false *@throws FileNotFoundException *@throws IOException */ public boolean copyfile(String sourcefile,String targetfile) throws java.io.FileNotFoundException,java.io.IOException { File v_sourcefile=new File(sourcefile); //取系统文件分隔符 separator=java.lang.System.getProperty("file.separator"); //取系统文件分隔符完 if(!v_sourcefile.exists()) return false; //取目标文件的路径 String tempstring=""; String tempstring1=targetfile; int j=0; int j1=separator.length(); int j2=targetfile.length(); j=tempstring1.indexOf(separator); while(j>=0) { tempstring+=tempstring1.substring(0,j); String tempstring2=tempstring1.substring(j+j1,j2); int j3=tempstring2.indexOf(separator); if(j3>=0) tempstring+=tempstring1.substring(j,j+j1); tempstring1=tempstring2; j2=tempstring1.length(); j=j3; } String newpath = tempstring; File f3=new File(newpath); if(f3.exists()) { if(!f3.isDirectory()) { return false; } } else { f3.mkdirs(); } java.io.FileInputStream file1=new java.io.FileInputStream(sourcefile); java.io.FileOutputStream file2=new java.io.FileOutputStream(targetfile); int abyte; while((abyte=file1.read())!=-1){ file2.write(abyte);} file1.close(); file2.close(); return true; } thanks,但当文件达到10M以上时,经常会出错 坐等高手!!!!输出到文本发生截断?何解? 【求助】关于jsp访问excel spring MVC中的声明式事务的管理问题 shindig 安装失败,404错误! JSP页面有利于网络爬虫等抓去么, jsp的乱码问题 求解决 感谢 两个下拉框的联动问题 问了问题后一定要记得揭贴!让我们共同把CSDN论坛做好,谢谢 小问题,好郁闷! 在线等待,如何在JSP中用Lotus Domino Toolkit提供的DCOMail发信? 请问最好用的,用来调试JSP页面的工具是什么?能否介绍一下呀? JSP中的一个打开无工具栏、状态栏的简单问题,100分相送!!!!
*功能:将一个文件复制粘贴到另一文件夹中,并可改名.路径为文件的绝对路径。
*@param sourcefile 源文件
*@param targetfile 目标文件
*@return true or false
*@throws FileNotFoundException
*@throws IOException
*/
public boolean copyfile(String sourcefile,String targetfile) throws java.io.FileNotFoundException,java.io.IOException
{
File v_sourcefile=new File(sourcefile);
//取系统文件分隔符
separator=java.lang.System.getProperty("file.separator");
//取系统文件分隔符完
if(!v_sourcefile.exists())
return false;
//取目标文件的路径
String tempstring="";
String tempstring1=targetfile;
int j=0;
int j1=separator.length();
int j2=targetfile.length();
j=tempstring1.indexOf(separator);
while(j>=0)
{
tempstring+=tempstring1.substring(0,j);
String tempstring2=tempstring1.substring(j+j1,j2);
int j3=tempstring2.indexOf(separator);
if(j3>=0)
tempstring+=tempstring1.substring(j,j+j1);
tempstring1=tempstring2;
j2=tempstring1.length();
j=j3;
}
String newpath = tempstring;
File f3=new File(newpath);
if(f3.exists())
{
if(!f3.isDirectory())
{
return false;
}
}
else
{
f3.mkdirs();
}
java.io.FileInputStream file1=new java.io.FileInputStream(sourcefile);
java.io.FileOutputStream file2=new java.io.FileOutputStream(targetfile);
int abyte;
while((abyte=file1.read())!=-1){
file2.write(abyte);}
file1.close();
file2.close();
return true;
}