我在打開文件時遇到了一些麻煩。嗯,我已經使用絕對路徑知道該文件,但它仍然無法打開該文件(未找到文件)找不到該文件
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(); }
}
我想這個問題是該設備還沒有文件,但如何我可以在應用程序啓動時上傳它嗎?
在此先感謝
你有沒有在你的manifest.xml給這個許可使用許可權的android:NAME =「android.permission.WRITE_EXTERNAL_STORAGE」 /> – Aerrow
是我但它沒有找到它: 06-04 16:50:36.674:W/System.err(24897):java.io.FileNotFoundException:/data/data/neves.ProjectNodes/files/Nodes.txt(No such文件或目錄) –