Java txt

阅读更多
package functions;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;

public class TxtReader {

public static void main(String[] args) {
System.out.println(getText(""));   
}

public static String getText(String filename){    
    String return_str = null;    
    try {    
        BufferedReader read = null;    
        try {    
            read = new BufferedReader(new FileReader(filename));    
            String str = "";    
            while ((str=read.readLine())!=null) {    
                return_str = return_str + str + "\r\n";    
            }    
        } catch (FileNotFoundException e) {    
            System.out.println("Something wrong when analysis the txt file");    
            e.printStackTrace();    
        }    
    } catch (Exception e) {    
        e.printStackTrace();    
    }    
    return return_str;    
}  

}

你可能感兴趣的:(Java txt)