2013-01-03 2 views
1
int reval = fcCari.showOpenDialog(this); 
String sourcePath = fcCari.getSelectedFile().getAbsolutePath(); 
String targetPath = "C:\\Users\\nadzar\\Downloads\\Compressed\\JavaSQLite\\resource\\"; 
    targetPath += fcCari.getSelectedFile().getName(); 
    if ((reval == JFileChooser.APPROVE_OPTION)) { 
      File source = new File(sourcePath); 
      File target = new File(targetPath); 
      copyFile(source, target); 
      targetPathFoto=targetPath; 
      tambahFoto(targetPathFoto); 
    } 
    else{ 
     JOptionPane.showMessageDialog(rootPane, "Batal Menambahkan Foto"); 
     tambahFoto(this.targetFoto); 
    } 
    System.out.println(targetPathFoto); 

내 프로젝트가 이동 한 경우 경로를 변경해야합니다. 프로젝트 디렉토리가 변경되는 동안 대상 경로가 어떻게 변경 될 수 있습니까?자바에서 프로젝트의 동일한 디렉토리에 복사 하시겠습니까?

+0

[this] (http://stackoverflow.com/questions/778187/getting-directory-path-to-class-file-containing-main)와 같은 것? –

답변

0

이 목적으로 속성 파일을 사용하십시오. 필요한 작업은 속성 값을 변경하는 것입니다.

# app home, build absolute paths in code using this path 
app.home=path_to_home_directory 

이러한 속성을 읽으려면 java.util.Properties을 사용하십시오.

mkyong에서 예를 참조하십시오.

+0

내 프로젝트의 디렉토리가 변경된 경우 어떻게해야합니까? 내가 깨끗하게하고 프로그램을 빌드한다면? – user1944789

+0

디렉토리를 변경하면 속성 파일에서'app.home'을 업데이트 할 것입니다 –

관련 문제