java把文件内容转成字符串或字符串数组

来源:百度知道 编辑:UC知道 时间:2024/05/18 08:57:16
如题,再有Stream Buffered Reader 等输入输出的特点,一般一个程序读取文件转成字符串或字符串数组,用那种方便节约

楼主可以参考此程序:
import java.io.*;

public class TestPrintStream {
public static void main(String[] args) {
String filename = args[0] ;
if(filename != null) {list(filename , System.out);}
}
public static void list(String f, PrintStream a) {
try {
BufferedReader k = new BufferedReader(new FileReader(f)) ;
String s = null;
while((s =k.readLine()) != null) {
a.println(s);
}
k.close();
} catch (IOException e) {
a.println("jasfgjayhfguaysfuyas");
}
}
}