首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

Java 操作 资料 File

2013-07-01 
Java 操作 文件 File?写文件public static void stream(Stringpath) throws FileNotFoundException, IOExc

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;      }  

??

?

热点排行