FileInputStream is a stream to grab the information from files.Combined with FileOutputStream, we can achieve the function of copying.

Examples:

public class Demo4 {
 
 public static void main(String[] args) {
  String content = null;
  byte[] buffer = new byte[1024];
  int size = 0;
  File file = new File("C:/Users/caich5/Desktop/aaaa.txt");
  InputStream input = null;
  try {
      input = new FileInputStream(file);
      OutputStream output = new FileOutputStream("C:/Users/caich5/Desktop/tttd.txt");
   while((size = input.read(buffer))!= -1){
    //show in console
    content = new String(buffer,0,size);
    System.out.println(content);
    //copy to another file
    output.write(buffer, 0, size);
   }
   input.close();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

 

Tips: FileInputStream,FileOutputStream,both of them are low lever stream.

 

相关文章:

  • 2022-01-10
  • 2021-05-22
  • 2021-05-18
  • 2022-12-23
  • 2021-04-29
  • 2021-11-22
  • 2021-11-24
猜你喜欢
  • 2021-10-30
  • 2022-02-11
  • 2021-10-24
  • 2021-09-08
  • 2021-09-29
  • 2022-12-23
相关资源
相似解决方案