我試圖讀取製表符分隔的txt文件並將數據放入字符串數組的兩列中。試圖將分隔的txt文件掃描到字符串數組中
package mailsender;
import java.io.*;
import java.util.Scanner;
public class MailSenderList {
static String address=null;
static String name=null;
static String[][] mailer;
// @SuppressWarnings("empty-statement")
public static void main(String[] args) throws IOException {
try {
Scanner s = new Scanner(new BufferedReader(new FileReader("/home/fotis/Documents/MailRecipients.txt"),'\t')); //This is the path and the name of my file
for(int i=0;i>=30;i++){
for(int j=0;j>=2;j++){
if (s.hasNext());{
mailer[i][j]=s.next(); //here i am trying to put 1st+2 word into first column and 2nd+2 into second column.
}
}
}
for(int ii=0;ii>=30;ii++){
System.out.println("Line : ");
for(int ji=0;ji>=2;ji++){
System.out.print(" " + mailer[ii][ji]);
//trying to print and check the array
}
}
}
catch (java.io.FileNotFoundException e) {
System.out.println("Error opening file, ending program");
//System.exit(1);}
}
}
class mail{
mail(){
}
}
}
文件成功生成,但沒有結果System.out.In
調試器,似乎它從來沒有從第一for
循環傳遞。
該代碼將永遠不會輸入for循環。你說我= 0,而我大於或等於30,這不是,所以它會退出循環。 – Ryan