Java 操作 资料 File
Java 操作 文件 File
写文件
public static void stream(String path) throws FileNotFoundException, IOException { Long startTime = System.currentTimeMillis(); BufferedReader reader = getReader(new File(path)); String line; while ((line = reader.readLine()) != null) { // 空转 System.out.println(line); } Long estimatedTime = System.currentTimeMillis() - startTime; System.out.printf("stream Diff: %d ms\n", estimatedTime); }
读文件
public static void stream(String file) throws FileNotFoundException, IOException { Long startTime = System.currentTimeMillis(); BufferedReader reader = getReader(new File(path)); String line; while ((line = reader.readLine()) != null) { // 空转 System.out.println(line); } Long estimatedTime = System.currentTimeMillis() - startTime; System.out.printf("stream Diff: %d ms\n", estimatedTime); }
public static BufferedReader getReader(File f) throws FileNotFoundException, IOException { BufferedReader reader = null; if (f.getName().endsWith(".gz")) { reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(f)))); } else { reader = new BufferedReader(new InputStreamReader(new FileInputStream(f))); } return reader; }