我正在为我的工作编写一个有趣的程序,主要供我使用,但是问题是它将在netbeans编辑器中运行,但是如果我构建该项目,则在使用.jar时它将无法运行。

public class finalprogram {
    public static void main(String[] args) throws IOException {
                            String row;

        BufferedReader csvReader = new BufferedReader(new FileReader("target\\book1.csv"));//reads the csv

        while ((row = csvReader.readLine()) != null) {
            String[] data = row.split(",");//saves the data from each row seperated by a comma
            System.out.println(data[0]);
            File myFile = new File("target\\phones\\" + data[0] + ".cfg");//creates file location with the data recieved from the file read
            writer(myFile, data);
            if (myFile.createNewFile()) {
                System.out.println("File is created!");
            } else {
                System.out.println("File already exists.");
            }
        }

        csvReader.close();
    }

        static private void writer(File myFile, String[] data) throws IOException {
        FileWriter writer = new FileWriter(myFile);
        writer.write("#!version:1.0.0.1 \n");
        writer.write("## the file header \"#!version:1.0.0.1\" can not be edited or deleted. ##\n");

        writer.write("\naccount.1.auth_name = " + data[1]);
        writer.write("\naccount.1.display_name = " + data[2]);
        writer.write("\naccount.1.enable = 1");
        writer.write("\naccount.1.label = " + data[3]);
        writer.write("\naccount.1.password = " + data[4]);
        writer.write("\naccount.1.sip_server.1.address = " + data[5]);
        writer.write("\naccount.1.sip_server.1.expires = ");
        writer.write("\naccount.1.sip_server.1.failback_mode = 0");
        writer.write("\naccount.1.sip_server.1.failback_timeout = ");
        writer.write("\naccount.1.sip_server.1.port = 0");
        writer.write("\naccount.1.sip_server.1.register_on_enable = 0");
        writer.write("\naccount.1.sip_server.1.retry_counts = ");
        writer.write("\naccount.1.user_name = " + data[6]);
        writer.write("\n");
        writer.write("\n");

        writer.close();
    }
}



该程序将获取一个csv并创建用于电话的.cfg文件,其中包含预设信息,如果我在netbeans中运行它,它将在编辑器中运行,它将完成工作并正常工作,但是一旦我构建并尝试使用.jar可执行文件将不起作用。我需要帮助吗?还是这个netbeans无法正常工作?

最佳答案

我用Gradle弄清楚了,我需要使用发行版文件夹中的文件,然后使用它制作的Windows批处理文件夹来运行程序

关于java - 程序将基于Netbeans 11.2构建,但jar文件不会执行它应该执行的操作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59565426/

10-10 16:36
查看更多