Java 使用从文本/写入到文本的公式

Java 使用从文本/写入到文本的公式,java,Java,因此,我的讲座powerpoint幻灯片甚至我的书对我的理解来说都不是很好,那就是解释如何使用文本文档中的公式,然后当代码成功运行/编译时,它将在同一文件夹中创建Results.txt 这些是记事本文档中的公式。没什么疯狂的,只是一个概念的证明 4 * 5 .. 3 / 4... 3 - 1.. 2+3 这里有一些东西可以让你开始。//TODO:comments是您需要构建逻辑的地方。确保将文件路径更改回所需的路径。我把它们换成了临时位置。同时更改打印的消息,因为我只是在那里放了一些东西作为概念

因此,我的讲座powerpoint幻灯片甚至我的书对我的理解来说都不是很好,那就是解释如何使用文本文档中的公式,然后当代码成功运行/编译时,它将在同一文件夹中创建Results.txt

这些是记事本文档中的公式。没什么疯狂的,只是一个概念的证明 4 * 5 .. 3 / 4... 3 - 1.. 2+3


这里有一些东西可以让你开始。//TODO:comments是您需要构建逻辑的地方。确保将文件路径更改回所需的路径。我把它们换成了临时位置。同时更改打印的消息,因为我只是在那里放了一些东西作为概念证明。我试图彻底地发表评论,但毫不犹豫地提出问题

import java.io.*;
import java.util.*;

public class ReadFileLineByLine {

public static void main(String[] args) throws FileNotFoundException {
    String line = "";
    //Declare Scanner and PrintWriter outside of try clause so they can be closed in finally clause
    Scanner input = null;
    PrintWriter output = null;

    try {
        //Instantiate input and output file
        input = new Scanner(new File("C:\\Temp\\test.txt"));
        output = new PrintWriter(new File("C:\\Temp\\Results.txt"));

        //Loop through lines in input file
        while (input.hasNextLine()) {
            line = input.nextLine();

            // Display message to commandline
            System.out.println("read <" + line + ">"); 

            // Populate ArrayList of tokenized formula from String line
            //TODO:

            // The variable to store result of the operation
            double result = 0; 

            // Determine the operator and calculate value of the result
            //TODO:

            // Write result to file
            output.println("Print result of " + line + " to Results.txt");
        }
    } catch (FileNotFoundException e) {
        //Exception thrown, print message to console
        System.out.println("File Not Found: " + e.getMessage());
    } finally {
        //close files in finally clause so it happens even if exception is thrown
        //I also set to null as extra precaution
        input.close();
        input = null;
        output.close();
        output = null;
    }
}
}

4 * 5.. 3 / 4.. 3 - 1.. 2+3..那里有许多编译时错误。你到底在问什么?ReadFileLineByLine.java:22:错误:非法转义字符扫描程序输入=新扫描程序新文件C:\Users\Frost\Documents\Question4。。。。。。。它有一个^指向每个部分。我不明白为什么。此外,如果我的代码方向正确?要修复非法转义字符,必须在文件路径Scanner input=new Scanner new FileC:\\Users\\Frost\\Documents\\Question4中的反斜杠上加倍;否则它会认为单个反斜杠是一个转义字符。在编译错误修复后再次发布代码,我们可以帮助处理逻辑。我认为纠正错误也会帮助您理解逻辑。如果需要,询问其他错误:非常感谢你!我将使用此模板,看看是否可以获得它。如果需要,将用问题进行评论!:
import java.io.*;
import java.util.*;

public class ReadFileLineByLine {

public static void main(String[] args) throws FileNotFoundException {
    String line = "";
    //Declare Scanner and PrintWriter outside of try clause so they can be closed in finally clause
    Scanner input = null;
    PrintWriter output = null;

    try {
        //Instantiate input and output file
        input = new Scanner(new File("C:\\Temp\\test.txt"));
        output = new PrintWriter(new File("C:\\Temp\\Results.txt"));

        //Loop through lines in input file
        while (input.hasNextLine()) {
            line = input.nextLine();

            // Display message to commandline
            System.out.println("read <" + line + ">"); 

            // Populate ArrayList of tokenized formula from String line
            //TODO:

            // The variable to store result of the operation
            double result = 0; 

            // Determine the operator and calculate value of the result
            //TODO:

            // Write result to file
            output.println("Print result of " + line + " to Results.txt");
        }
    } catch (FileNotFoundException e) {
        //Exception thrown, print message to console
        System.out.println("File Not Found: " + e.getMessage());
    } finally {
        //close files in finally clause so it happens even if exception is thrown
        //I also set to null as extra precaution
        input.close();
        input = null;
        output.close();
        output = null;
    }
}
}