我想如果password.txt存在,程序什么也不做,转到下一行,如果不存在password.txt,则创建此文件并在其上写入123456 但是程序会写在password.txt 123456上!我错在哪里?
File file = new File(getExternalCacheDir(), "/sdcard/Robo/password.txt" );
if (!file.exists()) {
try {
password="123456";
File passfile = new
File("/sdcard/Robo/password.txt");
passfile.createNewFile();
FileOutputStream passout = new
FileOutputStream(passfile);
OutputStreamWriter passoutw = new
OutputStreamWriter(passout);
passoutw.append(password);
passoutw.close();
passout.close();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
答案 0 :(得分:0)
File file = new File("/sdcard/Robo/password.txt" );