java读文件用字符流比用字节流快,有缓存比无缓存快。
下面是一个用于解析文件:
下面是一个用于解析文件:
- import java.io.FileInputStream;
- public class TestReadFiles {
- public static void main(String[] args){
- System.out.println(new String(TestReadFiles.testReadFile("d://test.txt")));
- // 注意"/"的转义"//"
- }
- public static byte[] testReadFile(String fileNames){
- String original = null;
- FileInputStream fis = null;
- byte[] bytes = null;
- byte[] result = null;
- try{
- fis = new FileInputStream(fileNames);
- bytes = new byte[fis.available()];
- fis.read(bytes);
- original = new String(bytes);
- result = original.getBytes();
- }
- catch(Exception ex){
- ex.printStackTrace();
- }
- return result;
- }
- }