【问题标题】:Change path to file with Maven Ant使用 Maven Ant 更改文件路径
【发布时间】:2015-10-26 10:05:07
【问题描述】:

我对 Mavan 和 ant 很陌生。我有这样的简单项目:

public class test {

    public test() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        String path = "test\\template.txt"
        FileOutputStream fileOut = new FileOutputStream(path);
    }
}

我只想更改我的字符串“路径”表单蚂蚁任务。 我可以这样做吗?如果是,请告诉我如何。

【问题讨论】:

  • Ant 和 MAven 是构建工具。你问的看起来更像是应用程序的不同论点。如果您是 Java 开发新手,请离开 Ant 和 Maven,下个月休息。
  • 还将测试类从应用程序类中分离出来

标签: java maven ant


【解决方案1】:

建议

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class Application {

    public Application() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) throws FileNotFoundException {
        if (args.length < 1) {
            System.out.println("Usage " + Application.class.getSimpleName() + " template-file");
        }

        String pathStr = args[0];
        File path = new File(pathStr);
        if (path.exists()) {
            System.err.println("Already a file exists at location '" + path + "'");
        }

        FileOutputStream fileOut = new FileOutputStream(path);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-25
    • 1970-01-01
    • 2015-06-26
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 2013-12-06
    相关资源
    最近更新 更多