在Java中删除文件中最后一个字符的最简单方法是什么?
答案 0 :(得分:0)
您可以使用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) {
}