doublesを含むファイルを読み取ろうとしています。10進数を読み取ろうとすると、問題が発生することがわかりました。整数の場合、すべてが正常に機能します。例外が発生してNoSuchElementException
います。私の問題を解決する方法について何かアイデアはありますか?私のコード:
public class readd {
protected Formatter output;
protected Scanner input = new Scanner(System.in);
private Scanner in = new Scanner(System.in);
protected FileWriter out;
protected BufferedWriter out1;
private String ss;
public int r=1,c=1;
public double[][] output_matrix = null;
public double[][] output_matrix2 = null;
public double[] lap_time = null;
public readd() {
}
public void OpenFileRead(String fileName) { //anoigma tou arxeiou gia diavasma
try {
input = new Scanner(new File(fileName));
System.out.println(fileName);
} catch (FileNotFoundException e) { //sfalma kata tin evresi kai to anoigma tou arxeiou
System.err.println("Sfalma kata to anoigma toy arxeioy");
System.exit(0); //eksodos
}
}
public void Load() { //anagnwsi dedomenwn apo arxeio
// double[][] w1 = null;
int count = 0;
int row = 0, col = 0;
// double [][] w1=null;
try {
while (input.hasNext()) { //oso tha iparxei apothikeumeni eggrafi
count++;
if (count == 1) {
row = input.nextInt();
r = row;
// System.out.println(row);
continue;
} else if (count == 2) {
col = input.nextInt();
// System.out.println(col);
c = col;
continue;
} else {
// System.out.println("col="+col);
output_matrix = new double[row][col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
output_matrix[i][j] = input.nextDouble();
//String ss=new Integer(input.nextInt()).toString();
//w1[i][j]=Double.parseDouble(ss.trim());
// String s1 = new Integer(input.nextInt()).toString();
//double v = Double.parseDouble(s1.trim());
//String s2 = new Integer(input.nextInt()).toString();
//int s = Integer.parseInt(s2.trim());
// System.out.print(output_matrix[i][j]+" ");
}
// System.out.println(" ");
}
//System.out.print(col);
//System.out.print(row);
}
}
} catch (NoSuchElementException e) {
System.err.println("Sfalma kata ti tropopoisisi toy arxeioy");
System.err.println(e.getMessage()); //emfanisi tou minimatos sfalmatos
input.close();
System.exit(0);
} catch (IllegalStateException e) {
System.err.println("Sfalma kata ti anagnosi toy arxeioy");
System.exit(0);
}
}
}
public static void main(String[] args) {
// TODO code application logic here
double[][] wa1;
readd w = new readd();
w.OpenFileRead("W1.txt");
w.Load();
wa1 = w.output_matrix;
}here