2014-06-09 4 views
1

에있는 문자열로 변환하고 텍스트보기로 인쇄하십시오. 폴더가 sdcard에있는 경우 앱을 실행할 때마다 매번 json fron을 가져 와서 폴더를 만듭니다. 그러면 json을 수동으로 삽입합니다. 나는 SD 카드의 DOR 폴더 또는 /sdcard/dor/bottomText.json이었다 String에서 bottomText.json 변환, 그리고 난 그것을 보여 TextView을 사용하는 방법이있다json 파일을 sd 카드

+1

질문을 다시 작성하십시오. 제목이 너무 길고 혼란 스럽습니다. – Sufian

답변

1

.

 FileReader inputStream = null; 
      JSONObject obj1; 


     try { 


      String line,line1=""; 
      String path; 
       File sdcard = Environment.getExternalStorageDirectory(); 
       File f=new File(sdcard+"/dor"); 

       f.mkdir(); 
       File file1 = new File(sdcard,"/dor/fitness.json"); 
       //file1.mkdir(); 
       // Assuming each link to be on a new line 
      StringBuilder text = new StringBuilder(); 

        String json1 = null; 
        try { 

         InputStream is1 = new FileInputStream(file1); 

         int size1 = is1.available(); 

         byte[] buffer = new byte[size1]; 

         is1.read(buffer); 

         is1.close(); 

         json1 = new String(buffer, "UTF-8"); 


      } catch (IOException ex) { 
       ex.printStackTrace(); 
       return; 
      } 

    TextView tv = (TextView)findViewById(R.id.textView);  
     tv.setText(json1); 
     } catch (JSONException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 
+0

나는 흥분되는 것을 알고 있지만 귀하의 게시물 (질문/답변)을 적절하게 설명하십시오. 그것은 미래에 다른 사람들을 돕습니다. – Sufian

+0

실제로 답변과 내가 hav 일을 실제로 sdcard의 dor 폴더 또는 /sdcard/dor/bottomText.json에 있던 문자열의 bottomText.json 변환 및 텍스트보기를 사용하여 그것을 보여줍니다. –