Java “与”的区别是什么;路径.get(";).ToAbsolutionPath().toString()";及;System.getProperty(“user.dir”)“;在爪哇?
我正在编写一个Java “与”的区别是什么;路径.get(";).ToAbsolutionPath().toString()";及;System.getProperty(“user.dir”)“;在爪哇?,java,path,Java,Path,我正在编写一个java代码来压缩给定位置(目标)中的目录(源)。到目前为止,我已经构建了代码和测试用例。我的疑问是在使用版本控制时,目标和源路径的路径定义。为了避免导致构建中断的冲突,我在引用的代码中看到路径设置如下: 源路径- zipRequest.setSource(Paths.get("").toAbsolutePath().toString() + "/src/main/resources/zipSource/source.txt"); zipRequest.setDestinatio
java
代码来压缩给定位置(目标)中的目录(源)。到目前为止,我已经构建了代码和测试用例。我的疑问是在使用版本控制时,目标和源路径的路径定义。为了避免导致构建中断的冲突,我在引用的代码中看到路径设置如下:
源路径-
zipRequest.setSource(Paths.get("").toAbsolutePath().toString() + "/src/main/resources/zipSource/source.txt");
zipRequest.setDestination(System.getProperty("user.dir") + "/src/main/resources/zipDestination/destination.zip");
及
目标路径-
zipRequest.setSource(Paths.get("").toAbsolutePath().toString() + "/src/main/resources/zipSource/source.txt");
zipRequest.setDestination(System.getProperty("user.dir") + "/src/main/resources/zipDestination/destination.zip");
我的问题是,
提前感谢!
路径。get(“”)。toAbsolutePath()。toString()
是当前的工作目录;您启动程序时所在的位置。它与System.getProperty(“user.dir”)
完全相同,我更喜欢第二个目录(它更短,并且在功能上更明显)但是,由于它们是相同的东西,您可以使用其中一个(或两者)来确定源和目标。然后允许使用System.getProperty(“user.dir”)
(或path.get(“”).toabsolutionPath().toString()
)对于测试类中的每个测试用例。我说的对吗?不知道。可能取决于您的测试;如果它们依赖于与当前文件夹相关的内容,则可以将两者都替换为“”。