我试图从visual basic写的文本文件中读取。当我使用bufferedReader类给我的readline方法时,我在行的开头得到随机的“fluff”。我试图懒惰,只是用子串(不好主意)切掉符号,但我真的想明白为什么我会得到这个以及我能做些什么来阻止它 这是与错误有关的VB代码:
total = CStr(co1) + " " + CStr(co2) + " " + CStr(co3) + " " + CStr(constant) + " "
My.Computer.FileSystem.WriteAllText("C:\Users\Server 1\Documents\Visual Studio 2012\Projects\RationalRouteGUI\RationalRouteGUI\res\readWrite.txt", total, False)
这是文本文件的文字:
5 5 5 5
这是我给出的错误:
5 5 5 5 Exception in thread "main" java.lang.NumberFormatException: For input string: "5"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at CalcMain.main(CalcMain.java:27)
5
5
5
5
这是代码,我将在#'中列出问题区域。
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
public class CalcMain {
public static void main(String []args) throws IOException{
int leadCoeff, secCoeff, thirdCoeff, finCon;
String total="";
String[] strFormula= {" "," "," ", " "};
int[] formula= {1,1,1,1};
BufferedReader fileRead = new BufferedReader(new FileReader("C:\\Users\\Server 1\\Documents\\Visual Studio 2012\\Projects\\RationalRouteGUI\\RationalRouteGUI\\res\\readWrite.txt"));
// PrintWriter fileOut = new PrintWriter("C:\\Users\\Server 1\\Documents\\Visual Studio 2012\\Projects\\RationalRouteGUI\\RationalRouteGUI\\res\\readWrite.txt");
try {//#############################################################
total= fileRead.readLine();
} catch (IOException e) {
e.printStackTrace();
}
System.out.print(total);
//####################################################################3
for(int x=0; x<4;x++){
strFormula[x]= total.substring(0,total.indexOf(" ")); //leadCoeff
total=cutString(strFormula[x],total);
System.out.println(strFormula[x]);
}
leadCoeff= Integer.parseInt(strFormula[0]);
secCoeff= Integer.parseInt(strFormula[1]);
thirdCoeff=Integer.parseInt(strFormula[2]);
finCon=Integer.parseInt(strFormula[3]);
fileRead.close();
}
public static String cutString(String in, String total) {
int index= total.indexOf(in);
total.substring(0,index);
return total;
}
}