JAVA基础补漏--文件读取


public class Test2 {


    public static void main(String[] args) throws IOException {

        FileInputStream fis = new FileInputStream("1.txt");
        int len = 0;
        byte[] bytes = new byte[200];
        while ((len = fis.read(bytes)) != -1)
        {
            System.out.println(len);
            System.out.println(new String(bytes,0,len));
        }


    }



}

文件复制


public class Test2 {


    public static void main(String[] args) throws IOException {

        FileInputStream fis = new FileInputStream("C:\\sdcs\\1.png");

        FileOutputStream fos = new FileOutputStream("D:\\sdcs\\1.png");

        int len = 0;
        byte[] bytes = new byte[1024];
        while ((len = fis.read(bytes)) != -1)
        {
            
            fos.write(bytes,0,len);
        }

        fos.close();
        fis.close();




    }



}

相关文章:

  • 2022-01-14
  • 2021-07-19
  • 2021-10-18
  • 2022-01-19
  • 2022-03-06
  • 2021-11-26
  • 2022-02-28
  • 2021-06-09
猜你喜欢
  • 2022-02-12
  • 2021-08-15
  • 2021-09-30
  • 2021-10-27
  • 2022-12-23
  • 2021-08-23
  • 2021-08-16
相关资源
相似解决方案