Leer y escribir archivos, leer archivos binarios, archivos bin

Leer y escribir archivos, leer archivos binarios, archivos bin

jokewinl  2019-03-27 10:12:30   4616   Colección 2

Transferencia desde:  https://blog.csdn.net/jokewinl/article/details/88837791

Columna de categoría:   Etiqueta del artículo de JavaIO

derechos de autor

Leer archivos ordinarios

			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

Leer archivo binario

				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

Escribir archivo

				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();

Supongo que te gusta

Origin blog.csdn.net/u010689853/article/details/110957360
Recomendado
Clasificación