Home > Back-end >  BufferedWriter writing files, less than the original file data, how to remove the rest of the garbag
BufferedWriter writing files, less than the original file data, how to remove the rest of the garbag

Time:04-09

TXT file zhongyuan data:
C210113X331
Sweep C210113X371 f code
C210113X450
After the operation data:
C210113X331
C210113X371
C210113X450
0113 x450
Check the operation process, found to be the "has swept yards after" writing the original data is covered, but new data cannot completely cover the original data, the portion of the data is still remaining behind "0113 x450",
The code is as follows:
Private void again (Uri Uri, List The list) {
//the File File=new File (mFilePath);
If (uri!=null& & The list!=null) {
Try {
AssetFileDescriptor newassetFileDescriptor=this. GetContentResolver (). OpenAssetFileDescriptor (uri, "w");
FileOutputStream outputStream=newassetFileDescriptor. CreateOutputStream ();
OutputStreamWriter OutputStreamWriter=new OutputStreamWriter (outputStream);
BufferedWriter BufferedWriter=new BufferedWriter (outputStreamWriter);
For (String s: list) {
If (s!=null) {
BufferedWriter. Write (s);
BufferedWriter. NewLine ();
BufferedWriter. Flush ();
}
}
BufferedWriter. Close ();
} the catch (Exception e) {
e.printStackTrace();
}
} else {
Toast. MakeText (check. This "file does not exist," Toast. LENGTH_LONG), show ();
}
}

How to solve it?
  • Related