Reputation: 429
I am writing a java
code to zip a directory (source)in a given location (destination). I have built the code and test cases up to this point. The doubt I have is about the path defining of destination and source paths while working with version control. To avoid conflicts which result in to build breaks, I have seen in a code I referred that the paths were set as follows;
Source Path-
zipRequest.setSource(Paths.get("").toAbsolutePath().toString() + "/src/main/resources/zipSource/source.txt");
and
Destination Path-
zipRequest.setDestination(System.getProperty("user.dir") + "/src/main/resources/zipDestination/destination.zip");
My questions are;
Thanks in advance!
Upvotes: 3
Views: 726
Reputation: 201447
Paths.get("").toAbsolutePath().toString()
is the current working directory; where you were when you launched the program. It is exactly the same thing as System.getProperty("user.dir")
and I would prefer the second one (it's shorter, and more obvious in what it does). But, since they are the same thing, you can use either (or both) for determining the source and destination.
Upvotes: 2