2012-06-04 18 views
0

파일을 여는 데 약간의 문제가 있습니다. 잘 난 이미 파일이 어디 있는지 알고 절대 경로를 사용했지만 여전히 파일 (파일을 찾을 수 없습니다) 나는 문제가 장치가 파일을하지 않았 음을 추측파일을 찾을 수 없습니다

public void ReadFromFile() throws FileNotFoundException 
{ 
     /** Read the contents of the given file. */ 


     String SourceID = new String(); 
     String LogicalID = new String(); 

     File fileDir = getFilesDir(); 
     String s = new String(); 

     s+=fileDir.getAbsolutePath()+"/Nodes.txt"; 
     Scanner scanner = new Scanner(new FileInputStream(s)); 


     try 
     { 
      while (scanner.hasNextLine()) 
      { 

       SourceID = scanner.nextLine(); 
       LogicalID = scanner.nextLine(); 
       String ss = new String(); 
       ss+=" ----------------> "+SourceID+" "+LogicalID+" "; 

       Log.v(TAG, ss); 
       ListaNodesSTART.add(new NodesToStart(SourceID,LogicalID)); 
      } 
     }catch(Exception ee){//Log.v(TAG, "Could not read the file"); 
      ERROR.setText("Could Not Read file Nodes.txt"); 
     ErRorLog.setText("Could Not Read file Nodes.txt");} 

     finally{scanner.close(); } 
    } 

을 열 질수 있지만, 어떻게 앱을 시작할 때 업로드 할 수 있습니까?

미리 감사드립니다.

+0

당신이 당신의 manifest.xml에이 권한을 준 한 일은 사용 - 권한 안드로이드 : 이름 = "android.permission.WRITE_EXTERNAL_STORAGE"/> – Aerrow

+0

네 하지만 어쨌든 그것을 찾지 못했습니다 : 06-04 16 : 50 : 36.674 : W/System.err (24897) : java.io.FileNotFoundException : /data/data/neves.ProjectNodes/files/Nodes.txt (No such such 파일 또는 디렉토리) –

답변

0

언급 한대로 파일이 없습니다. 다음 자산 폴더에 삽입하고, 정적 파일로 작업하려면 :

AssetManager assetManager = getAssets(); 
String[] files = null; 
try { 
    files = assetManager.list(""); 
} catch (IOException e) { 
    Log.d("tag", e.getMessage()); 
} 
for(String filename : files) { 
    if(filename.equals("Nodes.txt") { 
     InputStream in = null; 
     try { 
      // Do your work with file 
      in = assetManager.open(filename); 
      // ... 
     } catch(Exception e) { 
      Log.e("tag", e.getMessage()); 
     } 
    } 
} 
+0

그것은 남자를 일했다;) 고마워. .. 한가지 더 .. 죄송합니다, 멍청한 녀석 .. : -/내가 여기 스레드를 닫을 수 있습니까? 이 어리석은 질문에 대해 미안합니다 –

+0

InputStream을 닫는 것이 더 좋지만 여기에 스레드가 없습니다! 이 방법이 효과가 있으면 다른 사람들이 올바른 해결책을 찾을 수 있도록 답으로 받아 들여야합니다. –

+0

그래, 나도 알아,하지만 포럼에서 스레드에 대해 이야기하고 있었다. 이미 폐쇄 된 걸 볼 수 있습니다. 그게 내가 왜 똑같이해야하는지 궁금 해서요. –

관련 문제