区切り文字を使用して、「105878-798 ## 176000 ## JDOE」のような31行のドキュメントの最初の数字を引き出し、int配列に入れようとしています。私が興味を持っている番号は「105878798」であり、番号の数は一貫していません。
これを書きましたが、(行の)最初の区切り文字に達したときに行を変更する方法がわかりません。
import java.util.*;
import java.io.*;
public class Test {
public static void main(String[] args) throws Exception {
int n = 0;
String rad;
File fil = new File("accounts.txt");
int[] accountNr = new int[31];
Scanner sc = new Scanner(fil).useDelimiter("##");
while (sc.hasNextLine()) {
rad = sc.nextLine();
rad.replaceAll("-","");
accountNr[n] = Integer.parseInt(rad);
System.out.println(accountNr[n]);
n++;
System.out.println(rad);
}
}
}