기술 - Coding/Java

File Class의 경로 - 현재 작업하고 있는 프로젝트의 경로로

DoyoungJ 2017. 6. 26. 14:21


String filename = "Report.docx";
String workingDirectory = System.getProperty("user.dir");
String absoluteFilePath = "";

absoluteFilePath = workingDirectory + File.separator + filename;

InputStream doc = new FileInputStream(new File(docPath));




File 경로로 현재 작업하고 있는 프로젝트의 파일을 지정하고 싶을 때는, 위와 같이 System.getProperty("user.dir"); 로 작업 경로를 가져오고 File.separator로 작업 경로와 파일명 사이에 "\\" (windows), "/"(mac or linux)를 각 OS에 맞게 자동으로 넣어준다.