public static void readFileByBytes(String fileName) {
         File file = new File(fileName);
         InputStream in = null;
         try {
             System.out.println("以字节为单位读取文件内容,一次读一个字节:");
             // 一次读一个字节
             in = new FileInputStream(file);
             int tempbyte;
             while ((tempbyte = in.read()) != -1) {   
                 System.out.write(tempbyte);
             }
             in.close();   
         } catch (IOException e) {
             e.printStackTrace();
             return;
         }
         try {
             System.out.println("以字节为单位读取文件内容,一次读多个字节:");
             // 一次读100个字节
             byte[] tempbytes = new byte[100];
             int byteread = 0;
             in = new FileInputStream(fileName);
          

相关文章:

  • 2021-11-23
  • 2021-11-23
  • 2021-09-28
  • 2022-12-23
  • 2021-11-08
猜你喜欢
  • 2021-11-03
  • 2021-11-23
  • 2021-06-04
  • 2022-12-23
  • 2021-06-11
相关资源
相似解决方案