io流文本文档的快速读取
生活随笔
收集整理的這篇文章主要介紹了
io流文本文档的快速读取
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
package com.ute.action;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
?*?
?* @author Administrator
?* 文本文檔的快速讀取
?*/
public class action {
public static void main(String[] args) {
Long start=System.currentTimeMillis();
action.teIO();
}
public static void teIO(){
//通過反射的方式獲取流對象
File file1 = new File(action.class.getResource("utest.txt").getFile());
System.out.println("文件是否存在測試:"+file1.exists());//true
FileReader fr = null;
try {
fr= new FileReader(file1);
//修改每次讀取的個數,一般為2進制遞進64-128-256-512-1024
char [] c=new char[64];
while (fr.read(c) != -1) {
System.out.println(c);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
//關閉讀取流
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
?*?
?* @author Administrator
?* 文本文檔的快速讀取
?*/
public class action {
public static void main(String[] args) {
Long start=System.currentTimeMillis();
action.teIO();
Long end=System.currentTimeMillis();
System.out.print("用時");
}
public static void teIO(){
//通過反射的方式獲取流對象
File file1 = new File(action.class.getResource("utest.txt").getFile());
System.out.println("文件是否存在測試:"+file1.exists());//true
FileReader fr = null;
try {
fr= new FileReader(file1);
//修改每次讀取的個數,一般為2進制遞進64-128-256-512-1024
char [] c=new char[64];
while (fr.read(c) != -1) {
System.out.println(c);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
//關閉讀取流
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
總結
以上是生活随笔為你收集整理的io流文本文档的快速读取的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos安装 TA-Lib
- 下一篇: RunTime类,后台快速打开浏览器