2012-07-17 1 views
-1

내 .txt 파일의 데이터를 Android 클래스의 ReaderClass로 읽으려는 경우 필드가 ";"로 구분됩니다..txt 파일 (안드로이드)에서 intput 스트림을 얻는 방법은 무엇입니까?

---- 여기 내 내 마지막 게시물의 솔루션입니다 :

public void cut() 
    { 
    try{  


    InputStream input =context.getResources().openRawResource(R.raw.textfile); 
    BufferedReader br = null; 
    br=new BufferedReader(new InputStreamReader(input,"iso-8859-1")); 
    String line = null; 


    while ((line = br.readLine()) != null) {   

     String[] decoupage= line.split(";"); 


     String titre=decoupage[0]; 
     String description=decoupage[1]; 
     String reponse=decoupage[2]; 
     String explication=decoupage[3]; 
     String categorie=decoupage[4]; 
     String etat=decoupage[5];  

        //test Logcat 

      Log.d("information ", " buffer"); 
     Log.i("titre : ",titre); 
     Log.i("description : ",description); 
     Log.i("reponse : ",reponse); 
     Log.i("explication : ",explication); 
     Log.i("categorie : ",categorie); 
     Log.i("etat : ",etat); 



     } 
    in.close(); 

    }catch (Exception e){ 
    System.err.println("Error: " + e.getMessage()); 
    System.err.println("\n File not found"); 
    } 
    //end 
    } 
+1

이어야 당신이 질문을하기 전에 ** ** 것을 시도가! –

+0

다른 질문에 댓글을 달았습니다 : ** http://stackoverflow.com/questions/11483992/how-to-find-my-db-file-in-sqlite ** 당신이 그것에 대답 할 수 있고 저를 도울 수 있습니까? 내 지식을 늘리시겠습니까? –

답변

1
FileInputStream fis; 
fis = openFileInput("sample.txt"); 
StringBuffer Content = new StringBuffer(""); 

byte[] buffer = new byte[1024]; 
int length; 
while ((length = fis.read(buffer)) != -1) { 
    Content.append(new String(buffer)); 
} 

you will get entire content in a string buffer ,convert it into string, then you can apply yourString.split(";") to get all values which you can keep in some array. 
+0

여기서 필자는 필드 사이의 분리를 언급합니다; – Angelika

+1

문자열 버퍼를 문자열로 변환 한 다음 <문자열 변수 이름> .split (";")을 적용합니다. –

+0

감사합니다. StringTokenizer 클래스는 어떻습니까? – Angelika

관련 문제