日期:2014-05-20 浏览次数:20745 次
public class copy {
public static void main(String args[]) {
try{
FileInputStream inputStream=new FileInputStream(new File("飘.txt"));
FileOutputStream outputStream=new FileOutputStream(new File("test.txt"));
byte buf[]=new byte[1024];
while (inputStream.read(buf)!=-1) {
outputStream.write(buf);
}
outputStream.close();
System.out.println("end!");
}
catch(Exception e){
e.printStackTrace();
}
}
}
int len = -1;
while ((len = inputStream.read(buf)) != -1) {
outputStream.write(buf,0,len);
}
import java.io.*;
public class copy {
public static void main(String args[])
{
FileInputStream inputStream = null;
FileOutputStream outputStream = null;
try
{
inputStream = new FileInputStream(new File("飘.txt"));
outputStream = new FileOutputStream(new File("test.txt"));
byte buf[]=new byte[1024];
int len = 0;
while (len=inputStream.read(buf)!=-1)
{
//这句话的意思是,写出去多少合适?写到我len=-1之前的数据
outputStream.write(buf,0,len);
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
finally
{
try
{
if(inputStream!=null)
inputStream.close();
}
catch (IOException e)
{
System.out.println(e.toString());
}
try
{
if(outputStream!=null)
outputStream.close();
}
catch (IOException e)
{
System.out.println(e.toString());
}
}
}
}