1
我正在做一個簡單的應用程序,用java加載和保存文件。我試圖將其移植到Android,並且無法使其看到該文件。在android中加載和保存數據文件
我目前正在使用的文件路徑是
private static final String SAVE_FILE_PATH = "data/save";
下面是從文件加載數據的功能:
public void loadData() throws FileNotFoundException {
File file = new File(SAVE_FILE_PATH);
Scanner scanner;
if (file.exists()) {
scanner = new Scanner(new FileInputStream(file));
try {
while (scanner.hasNextLine()) {
allPlayers.add(new Player(scanner.nextLine()));
}
} finally {
scanner.close();
}
}
else {
System.out.println("No file found");
}
} finally {
scanner.close();
}
}
}
你的文件路徑應該是以下格式..「到/ mnt/SD卡/ yourfilename」 – itsrajesh4uguys
別t指望「/ mnt/sdcard」是正確的路徑。使用Environment.getExternalStorageDirectory() –