2013-07-24 1 views
-3

이미 여러 개의 txt 파일이 있습니다. 내 application.i에서이 파일을 읽고 txt 파일의 이름을 선택하고 읽습니다. 내가 어떻게? pls 나를 도와주세요. http://www.technotalkative.com/android-read-file-from-assets/휴대 기기의 안드로이드에있는 txt 파일에서 읽기

+0

하는이 질문은 http://stackoverflow.com/questions/12421814/how-to-read-text-file-in-android의 중복 될 수 있습니다

경로를 얻으려면 – snehal

답변

0

당신은

 AssetManager am = context.getAssets(); 

나는이 링크는 당신을 도울 수있는 생각하는 인텔리의 자산 디렉토리에 파일을 넣어 사용할 수 있습니다 파일.

File file = app.getFilesDir(); 
String path = file.getAbsoluteFile().getAbsolutePath() + "<filename.extension>"; 

-------------------------------------------------------- 

public static String readAllContents(String path) { 

    String fileContents = null; 

    try { 
     InputStream inputStream = new FileInputStream(path); 
     if (inputStream != null) { 
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream); 
      BufferedReader bufferedReader = new BufferedReader(inputStreamReader); 
      String receiveString = ""; 
      StringBuilder stringBuilder = new StringBuilder(); 

      while ((receiveString = bufferedReader.readLine()) != null) { 
       stringBuilder.append(receiveString); 
      } 

      inputStream.close(); 
      fileContents = stringBuilder.toString(); 
     } 
    } 

    catch (FileNotFoundException e) { 
     Log.e("exception", "File not found: " + e.toString()); 
    } catch (IOException e) { 
     Log.e("exception", "Can not read file: " + e.toString()); 
    } 

    return fileContents; 
} 
0

당신은 텍스트의 내용을 읽을 목록에 다음 코드를 사용할 수 있습니다