import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; //逐字节读取,复制 public class io1 {
public static void main (String []args) throws IOException{
//读文件
FileInputStream fis=new FileInputStream("D:\\Desktop\\文件复制练习\\1.jpg");
//1.要读取的对象(文件内的内容)
FileOutputStream fos=new FileOutputStream("D:\\Desktop\\文件复制练习\\3.jpg");
//单独进行写入,要确定写什么,写到什么地方
//要写入的对象(写入哪个文件) //确定读取方式:1.逐字节的读取,2.整个读取,
int a = fis.read();
// 读取每一个字节 while( a!= -){//读取的数据与-1比较
fos.write(a);
// 循环内先进行输出,后再次进行读取
a=fis.read(); //注意死循环 ,出现死循环因为没有a=
}
fis.close();//输入流
fos.flush();//
fos.close();//关闭输出流
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; public class io2 {
public static void main (String []args) throws IOException{
//读文件
FileInputStream fis=new FileInputStream("D:\\Desktop\\文件复制练习\\1.jpg");
//1.要读取的对象(文件内的内容)
FileOutputStream fos=new FileOutputStream("D:\\Desktop\\文件复制练习\\4.jpg");
//单独进行写入,要确定写什么,写到什么地方
//要写入的对象(写入哪个文件) //确定读取方式:1.逐字节的读取,2.整个读取, //整个读取
File f=new File ("D:\\Desktop\\文件复制练习\\1.jpg");
int c=(int)f.length(); //获取输入文件的长度
byte[]b=new byte [c];
//将文件字节长度。放入同样长度的数组中 int a = fis.read(b,,b.length); //读取数据 fos.write(b, , b.length);
fis.close();//输入流
fos.flush();//
fos.close();//关闭输出流
}
}
04-19 11:54
查看更多