//假设有如下文件:/Users/yue/Desktop/test.ev4
Path path = Paths.get("/Users", "yue", "Desktop", "test.ev4");
//注意,这种方式是错误的,即Path只会从第二个参数开始,自动添加文件分隔符,且第一个参数应该是有效路径
Path path = Paths.get(File.pathSeparator, "Users", "yue", "Desktop", "test.ev4");
public static byte[] readAllBytes(String fileName, long maxSize) throws IOException {
Path path = Paths.get(fileName);
long size = Files.size(path);
if (size > maxSize) {
throw new IOException("file: " + path + ", size:" + size + "> " + maxSize);
}
return Files.readAllBytes(path);
}
public static List<String> readAllLines(String fileName, Charset charset, long maxSize) throws IOException {
Path path = Paths.get(fileName);
long size = Files.size(path);
if (size > maxSize) {
throw new IOException("file: " + path + ", size:" + size + "> " + maxSize);
}
return Files.readAllLines(path, charset);
}