1 답변
-
Java7이나 8을 쓰시면 java.nio.file.Path를 쓰시면 됩니다. Path.resolve는 하나의 경로를 다른것과 합치는데 사용됩니다. 또 Paths클래스도 유용합니다.
Path path = Paths.get("foo", "bar", "baz.txt");
이런식으로 쓰시면 되는데요.Java7이전버전을 쓰시면 java.io.File로 이렇게하시면됩니다.
File baseDirectory = new File("foo"); File subDirectory = new File(baseDirectory, "bar"); File fileInDirectory = new File(subDirectory, "baz.txt");
문자열로 전달받고싶으시면 getPath()를 이용해서
public static String combine(String path1, String path2) { File file1 = new File(path1); File file2 = new File(file1, path2); return file2.getPath(); }
이런식으로 하시면 됩니다.
댓글 입력