读写文件,读二进制文件,bin文件

读写文件,读二进制文件,bin文件

jokewinl 2019-03-27 10:12:30  4616  收藏 2

转自 : https://blog.csdn.net/jokewinl/article/details/88837791

分类专栏: Java 文章标签: IO

版权

读普通文件

			FileReader reader = new FileReader(meFileName);
            BufferedReader br = new BufferedReader(reader);
            StringBuilder lines = new StringBuilder();
            while ((line = br.readLine()) != null) {
                // 一次读入一行数据
                lines.append(line);
            }
            line = lines.toString();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

读二进制文件

				bytesTo = new byte[fileLength.intValue()];
                DataInputStream read = new DataInputStream(new FileInputStream(new File(filePath)));

                read.read(bytesTo);
                read.close();
				
				System.arraycopy(filecontent,(i-1)*SIZEZ,bytes, 0,SIZEZ);//buty源数组,截取起始位置,截取后存放的数组,截取后存放的数组起始位置,截取数组长度
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

写入文件

				File meFile = new File(mePath);
				if(!meFile.exists()){
                        meFile.createNewFile();
                    }
                    FileWriter fw = new FileWriter(meFile.getAbsoluteFile()); //表示不追加
                    BufferedWriter bw = new BufferedWriter(fw);
                    bw.write(jsonObject.toString());
                    bw.close();

猜你喜欢

转载自blog.csdn.net/u010689853/article/details/110957360