2011-10-15 2 views
0

이 생성 된 파일의 경로는 어떻게 설정합니까? 사용자는 인수에 경로를 지정해야합니다. 현재이 코드는 파일을 생성 할 수 있습니다. 사용자는 원하는 곳에이 파일을 저장해야합니다. 나는 Netbeans에서 이것을하고있다.이 생성 된 파일의 경로를 인수로 설정하는 방법

File file = new File("Export.xml"); 
System.out.println(file.getName()); 
System.out.println(file.getAbsolutePath()); 

BufferedWriter bw = new BufferedWriter 
(new OutputStreamWriter(new FileOutputStream(file))); 
+3

인수를 허용하기 위해이 작은 스 니펫을 확장하는 데 어려움이 있습니까? – sarnold

+0

나는 그것을하는 방법을 모른다. 자바보다 새로운 것이다. – Sharada

+0

* "사용자는 인수에 경로를 지정해야합니다."* 사용자에게'JFileChooser'를 제공하십시오. –

답변

2

단순히 경로에 파일 이름을 추가하십시오.

public void export(String path) { 
    File file = new File(path + File.separator + "Export.xml"); 
    ... 
} 

public void caller() { 
    export("C:\\temp"); 
} 
관련 문제