2011-08-10 6 views

답변

24

때 createNewFile()는 다음과 같이 사용됩니다

File file = new File("data/data/your package name/test.txt"); 
if (!file.exists()) { 
     try { 
      file.createNewFile(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
} 

그래서 당신은 그것을 작성해야 파일을 말할 것이다. 패키지에 새 파일을 만들 수 있음을 기억하십시오. 그것은 "data/data/your package name /"입니다.

+0

내가 필요한 것입니다. 고마워. – teoREtik

0

현재 디렉토리에 저장됩니다 것은 당신의 classPath

0

가리키고있는 것은 당신이 파일 생성자에 전달하는 경로에 따라 다릅니다. 부모 디렉토리가 존재하고, 그 디렉토리에 쓰기 권한이 있다면 물론입니다.

4

아무튼 createNewFile()은 내 기기에서 전체 파일 경로를 만들지 못했습니다.

try { 
    if (!futurePhotoFile.exists()) { 
     new File(futurePhotoFile.getParent()).mkdirs(); 
     futurePhotoFile.createNewFile(); 
    } 
} catch (IOException e) { 
    Log.e("", "Could not create file.", e); 
    Crouton.showText(TaskDetailsActivity.this, 
      R.string.msgErrorNoSdCardAvailable, Style.ALERT); 
    return; 
} 
+0

이 스 니펫이 나를 위해 작동합니다. 감사합니다. –

+0

당신은 .... 환영합니다. :) – cV2

관련 문제