2014-09-11 7 views
1

그래서 기본적으로 나중에 볼 수 있도록 일부 로그를 텍스트 파일에 쓰려고합니다. 나는 에뮬레이터가 아닌 실제 전화로 이것을 실행하고있다. 나는 매우 다양한 변형을 시도해 왔으며, 가장 많은 것은 데이터/데이터 및 저장 장치에 에뮬레이트 된 것이지만 내 파일에는 액세스 할 수 없다. 어떤 도움을 주시면 감사하겠습니다. 내 최신 삭제되지 예제의 일부가되었습니다나중에 볼 수있는 안드로이드 저장 장치에 텍스트 파일 쓰기

String filename = "myfile.txt"; 
try { 
    File path = new File(context.getFilesDir(), "myfolder"); 
    if (!path.exists()) 
     path.mkdir(); 
    File output = new File(path, filename); 
    BufferedWriter buff = new BufferedWriter(new FileWriter(output)); 
    buff.append("hi"); 
    Log.d("Success", 
      "Successfully wrote a file " + context.getFilesDir()); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

final String appPath = String.format("%s/Datafiles", 
     context.getFilesDir()); 
File path = new File(appPath); 
if (!path.exists()) { 
    path.mkdir(); 
} 
String fileName = String.format("%s/filedemo.txt", appPath); 

및/저장 아래에 넣어 다음의

try { 
    String filename = "myfile.txt"; 
    File path = new File(Environment.getRootDirectory(), "myfolder"); 
    if (!path.exists()) 
     path.mkdir(); 
    File output = new File(path, filename); 
    BufferedWriter buff = new BufferedWriter(new FileWriter(output)); 
    buff.append("hi"); 
    Log.d("Success", 
      "Successfully wrote a file " + context.getFilesDir()); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

두/에뮬레이션/0/안드로이드/데이터/com.example.simplelte/files/system/stuff/test.txt 및 /storage/emulated/0/Android/data/com.example.simplelte/files/storage/emulated/0/stuff/test.txt 각각

try { 
    File file = new File(context.getExternalFilesDir(Environment 
      .getRootDirectory().getCanonicalPath()), "stuff"); 
    if (!file.mkdirs()) { 
     Log.e(LOG_TAG, "Directory not created"); 
    } 
    File output = new File(file, "test.txt"); 
    BufferedWriter buff; 
    buff = new BufferedWriter(new FileWriter(output)); 
    buff.append("hi"); 
    buff.close(); 
    Log.d("Success", output.getCanonicalPath()); 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

try { 
    File file = new File(context.getExternalFilesDir(Environment 
      .getExternalStorageDirectory().getCanonicalPath()), 
      "stuff"); 
    if (!file.mkdirs()) { 
     Log.e(LOG_TAG, "Directory not created"); 
    } 
    File output = new File(file, "test.txt"); 
    BufferedWriter buff; 
    buff = new BufferedWriter(new FileWriter(output)); 
    buff.append("hi"); 
    buff.close(); 
    Log.d("Success", output.getCanonicalPath()); 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

훨씬 더

. 나는 내가 생각할 수있는 모든 모범을 따라 갔다. 나는 문자 그대로 Computer \ Nexus 5 \ Internal storage \ 아래에서 텍스트 파일을보고 싶다. 나는 단순한 욕망을 가진 단순한 사람이다. 왜 이렇게 복잡해야합니까?

답변

0

시도해 보셨습니까?

File sdCard = Environment.getExternalStorageDirectory(); 
File dir = new File (sdCard.getAbsolutePath() + "/"); 
File file = new File(dir, "text.txt"); 

FileOutputStream f = new FileOutputStream(file); 
+0

방금 ​​해 보았습니다. 탐색기에서 파일을 볼 방법이 없습니다. /storage/emulated/0/text.txt를 만듭니다. – Ion