Java에서 파일의 마지막 문자를 삭제하는 가장 간단한 방법은 무엇입니까?파일에서 마지막 문자를 잘라내거나 자르는 가장 쉬운 방법
0
A
답변
-1
당신은 FileChannel truncate 사용할 수 있습니다
try {
File file = new File("fileToTruncate");
FileChannel fileChannel = new FileOutputStream(file, true).getChannel();
fileChannel.truncate(fileChannel.size() - 1); //Removes last character
fileChannel.close();
}
catch (FileNotFoundException ex) {
}
catch (IOException ex) {
}
[FileChannel.truncate()] (https://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html #truncate (long)) –
전체 파일의 마지막 문자를 실제로 의미합니까, 아니면 각 행의 마지막 문자를 의미합니까? – Bohemian