2013-07-21 2 views
-1

안녕하세요 안드로이드 외부 데이터 저장 장치에있는 모든 튜토리얼은 driveing하는 나 너트안드로이드 데이터 extstorage : 빠른 도움말하시기 바랍니다

i와 "부하가"잘 을 작품을 저장 "저장"버튼 2 개를 가지고 있지만 부하가 여기에하지 않는 OnOptionsCreatemenu이 내 코드는 내게 코드가 내게 대답하자 코드 도 내게 그것을 내 자신의 디렉토리에 저장할 수있게 해 줄까? ... iv 5 번 같은 스토리지에 저장하는 방법에 대한 모든 단일 튜토리얼을 읽어 ..... 그냥 그것을 얻으려면 바보에 메신저! (제발 링크 없음) 그러면 내 자신이 이해할 수있는 침팬지를 늦추어도 안드로이드 ext 데이터 저장소의 가장 단순한 고장이 될 것이기 때문에 새로운 튜토리얼로 만드십시오.

이것은 모두 코드 덩어리입니다. ..... 왜 코드가 2 개의 코드 상자에 표시되는지 확실하지 않습니다. ???)() {

String saveLine = ((EditText) 
      findViewById(R.id.captain)).getText().toString().trim(); 

    File sdcard = Environment.getExternalStorageDirectory(); 

    File file = new File(sdcard,"/myfile.txt"); 

    try { 

     FileWriter fw = new FileWriter(file); 

     BufferedWriter bw = new BufferedWriter(fw); 

     bw.write(saveLine); 

     bw.close(); 
     Toast.makeText(getApplicationContext(),"File saved!",Toast.LENGTH_LONG).show(); 
    } catch (IOException e) { 

     Toast.makeText(getApplicationContext(),"Error writing file!",Toast.LENGTH_LONG).show(); 

    } 
    { 

// 여기가 내가 변수를 둘 필요가 말한다 저장

개인 무효, 그것의 나의 처음

p.s 죄송합니다 ..... 쉽지? 왜 내가 save() 함수처럼 사용하게 할까?

private void load() { 

     // ensure(); 

     sdcard = Environment.getExternalStorageDirectory(); 

     File file1 = new File(sdcard,"/myfile.txt"); 


     try { 

      BufferedReader br = new BufferedReader(new FileReader(file1)); 

      String loadline; 

      if ((loadline = br.readLine()) != null) { 

       String content=loadline.toString(); 

       ((EditText) 
         findViewById(R.id.captain)).setText(content); 



      } 

      br.close(); 

     } 

     catch (IOException e) { 

      Toast.makeText(getApplicationContext(),"Error reading file!",Toast.LENGTH_LONG).show(); 

     } 

    } 
+0

나중에 지식을 얻으려는 경우, 눈살을 찌푸리게 될 때 게시물에 도움이나 비슷한 것을 넣어 두지 마십시오. SO에 오신 것을 환영합니다. – ObieMD5

+0

괜찮 았어. – OnTHEvERGEOFaANURYSM

답변

0

파일을 읽는 데 문제가있는 것 같습니다. SD 카드의 파일을 읽고 여기 EditText로 설정을위한 코드입니다 :

private void load(){ 

    File sdcard = Environment.getExternalStorageDirectory(); 

    //Get the text file 
    File file = new File(sdcard,"myfile.txt"); 

    //Read text from file 
    StringBuilder text = new StringBuilder(); 

    try { 
     BufferedReader br = new BufferedReader(new FileReader(file)); 
     String line; 

     while ((line = br.readLine()) != null) { 
      text.append(line); 
      text.append('\n'); 
     } 
    } 
    catch (IOException e) { 
     //You'll need to add proper error handling here 
     Toast.makeText(getApplicationContext(),"Error reading file!",Toast.LENGTH_LONG).show(); 
    } 

    //Find the view by its id 
    EditText ed = (EditText)findViewById(R.id.captain); 

    //Set the text 
    ed.setText(text); 
} 

정확한 출처 :이 다른 코멘트를하는 데 도움이 How can I read a text file from the SD card in Android?

희망.

+0

알았어. 그래서 개인 무효로드()() {..... 다음 귀하의 코드를 누른 다음 다시 "식이 예상"로드 사이에 던졌습니다() .... 사전에 도움을 주셔서 감사합니다. 로드 자체 메서드로 사용하려고 할 때 잘못 되었습니까? save() – OnTHEvERGEOFaANURYSM

+0

코드를 청소하고 다시 작성하는 것이 도움이되지 않습니까? –

+0

내가 "자바 : 불법적 인 표현의 시작"이라고 말하면 프로젝트를 다시 빌드하면 소스로 점프하여 개인 무효로드()를받습니다. 나는 또한 OnOpyionsCreateMenu에서 intelli j를 사용하고 있습니다. load()에 대한 case can not resolve method ?? – OnTHEvERGEOFaANURYSM

관련 문제