0
I am trying to create a file using the following chunk of code
String content = "This is the content to write into file";
File file = new File("/Users/abc/output.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileWriter fw;
try {
fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
모든 것이 예상대로 작동하지만, 현재 HTML 페이지와 관련된 폴더에 파일을 만들고 싶습니다. 어떻게 할 수 있습니까? 이렇게하면 내 작업 영역 밖에있는 파일을 작성/작성하고 있습니다.파일 쓰기를위한 상대 파일 경로
미리 감사드립니다.
_my 현재 HTML 페이지 란 무엇이라고 생각하십니까? –
첫 번째 슬래시 앞에 점 : ./myfolder – agamesh
위의 코드를 사용하여 txt 파일을 만드는 index.html (예를 들어)에서 서비스 호출을하고 있습니다. 이제는 output.txt 파일을 동일한 코드에 저장하려고합니다. 내 index.html 페이지로 –