如果我的文件在android中不存在

如果我的文件在android中不存在,android,file,Android,File,我想如果password.txt是存在的程序不做任何事情,并转到下一行,如果password.txt不存在它创建这个文件,并在它上面写123456 但无论如何程序都会在password.txt 123456上写!我哪里做错了 File file = new File(getExternalCacheDir(), "/sdcard/Robo/password.txt" ); if (!file.exists()) {

我想如果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();
                    }

                            }     
File file = new File("/sdcard/Robo/password.txt" );