我有一個x行數的文本文件。每行保存一個整數。當用戶點擊一個按鈕時,通過actionlistener執行一個動作,它應該列出文本文件上顯示的所有值。但是,現在我已將亞麻布設置爲10,意味着我已經告訴代碼只能處理10行文本文件。所以,如果我的文本文件只有3行/行的數據...它會列出這些行,其餘7行,它會吐出「空」。使用java從文本文件中讀取數據行
我記得有一種方法可以使用省略號讓程序知道你不知道確切的值,但最後它會根據給定的信息來計算它。我給出的信息將包含數字(數據)的行數。
下面是代碼的一部分。
private class thehandler implements ActionListener{
public void actionPerformed(ActionEvent event){
BufferedReader inputFile=null;
try {
FileReader freader =new FileReader("Data.txt");
inputFile = new BufferedReader(freader);
String MAP = "";
int linenum=10;
while(linenum > 0)
{
linenum=linenum-1;
MAP = inputFile.readLine();//read the next line until the specfic line is found
System.out.println(MAP);
}
} catch(Exception y) { y.printStackTrace(); }
}}
他會爲Google做什麼? – 2010-12-23 16:50:37
使用文件?那我每次遇到問題時都會做什麼 – Swine1973 2010-12-23 17:06:19