Ler e gravar arquivos, ler arquivos binários, arquivos bin
jokewinl 27/03/2019 10:12:30 4616 Coleção 2
Transferência de: https://blog.csdn.net/jokewinl/article/details/88837791
Coluna de categoria: Tag de artigo Java : IO
direito autoral
Leia arquivos comuns
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
Leia o arquivo binário
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
Gravar arquivo
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();