第1个回答 2009-04-22
package com;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Point {
public static void main(String[] args) {
Point p = new Point();
String path = "";// 你要读取的文件的路径 @example@
// "D:\\workspace\\JavaTest\\bin\\com\\a.txt"
p.outputMethod(path);
}
public void outputMethod(String path) {
try {
String[] arr = new String[1];
String[] temp;
BufferedReader br = new BufferedReader(new FileReader(path));
String line = br.readLine();
while (line != null) {
arr[arr.length-1] = line;
temp = new String[arr.length+1];
for(int i=0;i<arr.length;i++){
temp[i] = arr[i];
}
arr = new String[temp.length];
for(int i=0;i<arr.length;i++){
arr[i] = temp[i];
}
line = br.readLine();
}
br.close();
for(int i=0;i<arr.length-1;i++){
System.out.println(arr[i]);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}本回答被提问者采纳