有一个c:\a.txt文件,内容为:
abc cde de fd fd sdf
fds sdff sdf sdf sdf sdf
请问如何在java读取出来???????
我只能读取一行!!!
在线等.谢谢!
abc cde de fd fd sdf
fds sdff sdf sdf sdf sdf
请问如何在java读取出来???????
我只能读取一行!!!
在线等.谢谢!
FileReader fr = new FileReader("c:\\a.txt");
StringBuffer txt = new StringBuffer();
int k = fr.read();
while(k != -1){
txt.append((char)k);
k = fr.read();
}
fr.close();
System.out.println(txt);
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class CSDN2 {
public static void main(String[] args)
{
try {
BufferedReader read = new BufferedReader(new FileReader("C:\\a.txt"));
String str = null;
while((str = read.readLine())!=null)
{
String []array = str.split(" ");
for(int i=0 ; i < array.length ; i++)
{
System.out.println(array[i]);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}}