6 个解决方案
#1
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyFile
{
public static void main(String[] ags)
{
String srcFileName = "F:\\系统软件\\src.zip";
String targetFileName = "F:\\系统软件\\target.zip";
InputStream inStream = null;
try
{
inStream = new FileInputStream(srcFileName);
} catch (FileNotFoundException e)
{
System.err.println("读取文件[" + srcFileName + "]发生错误" + "\r\n"
+ e.getCause());
return;
}
File targetFile = new File(targetFileName);
OutputStream outStream = null;
try
{
targetFile.createNewFile();
outStream = new FileOutputStream(targetFile);
byte[] by = new byte[1024];
while (inStream.available() > 0)
{
inStream.read(by);
outStream.write(by);
}
} catch (IOException e)
{
System.err.println("创建文件[" + targetFileName + "]发生错误" + "\r\n"
+ e.getCause());
} finally
{
if (null != inStream)
{
try
{
inStream.close();
} catch (IOException e)
{
System.err.println(e.getCause());
}
}
if (null != outStream)
{
try
{
outStream.flush();
} catch (IOException e)
{
System.err.println(e.getCause());
}
try
{
outStream.close();
} catch (IOException e)
{
System.err.println(e.getCause());
}
}
}
System.out.println("复制完毕!");
}
}
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyFile
{
public static void main(String[] ags)
{
String srcFileName = "F:\\系统软件\\src.zip";
String targetFileName = "F:\\系统软件\\target.zip";
InputStream inStream = null;
try
{
inStream = new FileInputStream(srcFileName);
} catch (FileNotFoundException e)
{
System.err.println("读取文件[" + srcFileName + "]发生错误" + "\r\n"
+ e.getCause());
return;
}
File targetFile = new File(targetFileName);
OutputStream outStream = null;
try
{
targetFile.createNewFile();
outStream = new FileOutputStream(targetFile);
byte[] by = new byte[1024];
while (inStream.available() > 0)
{
inStream.read(by);
outStream.write(by);
}
} catch (IOException e)
{
System.err.println("创建文件[" + targetFileName + "]发生错误" + "\r\n"
+ e.getCause());
} finally
{
if (null != inStream)
{
try
{
inStream.close();
} catch (IOException e)
{
System.err.println(e.getCause());
}
}
if (null != outStream)
{
try
{
outStream.flush();
} catch (IOException e)
{
System.err.println(e.getCause());
}
try
{
outStream.close();
} catch (IOException e)
{
System.err.println(e.getCause());
}
}
}
System.out.println("复制完毕!");
}
}
#2
源文件没找到
#3
filenotfoundexception。
你读的文件存在吗?
你读的文件存在吗?
#4
to For_suzhen(不懂装懂):存在
to jxcfh():不行啊,显示的还是filenotfoundexception
to jxcfh():不行啊,显示的还是filenotfoundexception
#5
我把你的程序复制过来,然后在F盘建了一个"系统软件"文件夹,里面建了一个src.zip,编译执行通过!明显是你文件不存在了,程序是对的.
#6
哦,忘了说了,我验证的时候,用的是src.war,其实我是要复制一个war文件,因为觉得war就是一个zip文件,所以就这样问大家了。如果由于蔡鸟级引起的错误,还请大家理解。
#1
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyFile
{
public static void main(String[] ags)
{
String srcFileName = "F:\\系统软件\\src.zip";
String targetFileName = "F:\\系统软件\\target.zip";
InputStream inStream = null;
try
{
inStream = new FileInputStream(srcFileName);
} catch (FileNotFoundException e)
{
System.err.println("读取文件[" + srcFileName + "]发生错误" + "\r\n"
+ e.getCause());
return;
}
File targetFile = new File(targetFileName);
OutputStream outStream = null;
try
{
targetFile.createNewFile();
outStream = new FileOutputStream(targetFile);
byte[] by = new byte[1024];
while (inStream.available() > 0)
{
inStream.read(by);
outStream.write(by);
}
} catch (IOException e)
{
System.err.println("创建文件[" + targetFileName + "]发生错误" + "\r\n"
+ e.getCause());
} finally
{
if (null != inStream)
{
try
{
inStream.close();
} catch (IOException e)
{
System.err.println(e.getCause());
}
}
if (null != outStream)
{
try
{
outStream.flush();
} catch (IOException e)
{
System.err.println(e.getCause());
}
try
{
outStream.close();
} catch (IOException e)
{
System.err.println(e.getCause());
}
}
}
System.out.println("复制完毕!");
}
}
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyFile
{
public static void main(String[] ags)
{
String srcFileName = "F:\\系统软件\\src.zip";
String targetFileName = "F:\\系统软件\\target.zip";
InputStream inStream = null;
try
{
inStream = new FileInputStream(srcFileName);
} catch (FileNotFoundException e)
{
System.err.println("读取文件[" + srcFileName + "]发生错误" + "\r\n"
+ e.getCause());
return;
}
File targetFile = new File(targetFileName);
OutputStream outStream = null;
try
{
targetFile.createNewFile();
outStream = new FileOutputStream(targetFile);
byte[] by = new byte[1024];
while (inStream.available() > 0)
{
inStream.read(by);
outStream.write(by);
}
} catch (IOException e)
{
System.err.println("创建文件[" + targetFileName + "]发生错误" + "\r\n"
+ e.getCause());
} finally
{
if (null != inStream)
{
try
{
inStream.close();
} catch (IOException e)
{
System.err.println(e.getCause());
}
}
if (null != outStream)
{
try
{
outStream.flush();
} catch (IOException e)
{
System.err.println(e.getCause());
}
try
{
outStream.close();
} catch (IOException e)
{
System.err.println(e.getCause());
}
}
}
System.out.println("复制完毕!");
}
}
#2
源文件没找到
#3
filenotfoundexception。
你读的文件存在吗?
你读的文件存在吗?
#4
to For_suzhen(不懂装懂):存在
to jxcfh():不行啊,显示的还是filenotfoundexception
to jxcfh():不行啊,显示的还是filenotfoundexception
#5
我把你的程序复制过来,然后在F盘建了一个"系统软件"文件夹,里面建了一个src.zip,编译执行通过!明显是你文件不存在了,程序是对的.
#6
哦,忘了说了,我验证的时候,用的是src.war,其实我是要复制一个war文件,因为觉得war就是一个zip文件,所以就这样问大家了。如果由于蔡鸟级引起的错误,还请大家理解。