点击(此处)折叠或打开
- import java.io.File;
import java.io.FileOutputStream;
import java.io.RandomAccessFile;
import java.util.Iterator;
// 读取文件的最后一个字节。并判断是不是回车符\r
public class CutFile_Last1 {
public static void main(String[] args) {
String path = "C:/Users/lu13.xu/Desktop/333.txt";
System.out.println(checkLastByteIsEnter(path));
}
public static boolean checkLastByteIsEnter(String path) { -
File file = new File(path);
if (file.length() == 0) {
return true;
} -
try (RandomAccessFile raFile = new RandomAccessFile(file, "rw");) {
raFile.seek(file.length() - 1);
return '\r' == (char)raFile.read();
} catch (Exception e) {
} -
return false;
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30229789/viewspace-2121049/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/30229789/viewspace-2121049/