文本文件
[第 1 行] a=5
[第 2 行] b=2
[第 3 行] c=3
[第 4 行] a+b*c
我只想读取和输出第 4 行。如何?
而且,我想读取这些 a=5, b=2, c=3 并将其传递给一个整数值(变量)
public static void main(String[] args) throws IOException {
try {
File file = new File("D:\\TextFile.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line);
}
fileReader.close();
String input = stringBuffer.toString();
String output;
InToPost theTrans = new InToPost(input);
output = theTrans.doTrans();
System.out.println("Postfix is: " + output + '\n');
} catch (IOException e) {
e.printStackTrace();
}
}