Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
保存文件并不总是适用于android_Android_File_Save - Fatal编程技术网

保存文件并不总是适用于android

保存文件并不总是适用于android,android,file,save,Android,File,Save,所以一开始按钮有问题,只意味着我的文件有问题。我想将数字保存到我的文件中,以及我选择的语言。这种语言工作得很完美,但当我试图用我的数字做同样的事情时,它就错了 这是我的语言文件的代码 french.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try{ buttonSound.start();

所以一开始按钮有问题,只意味着我的文件有问题。我想将数字保存到我的文件中,以及我选择的语言。这种语言工作得很完美,但当我试图用我的数字做同样的事情时,它就错了

这是我的语言文件的代码

french.setOnClickListener(new View.OnClickListener() {  
        public void onClick(View v) {
            try{
                buttonSound.start();
                String FILENAME = "LangFile";
                String data ="FR";
                FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
                fos.write(data.getBytes());
                fos.close();
                FILENAME="TempFile";
                data="0";
                FileOutputStream fostemp = openFileOutput(FILENAME, Context.MODE_PRIVATE);
                fostemp.write(data.getBytes());
                fostemp.close();
                startActivity(new Intent("com.technopolisapp.LOGOTECHNOPOLIS"));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            finally{
                finish();
            }               
        }
    }); 
这里我为按下的按钮保存了两个字母 这是一段代码,它会再次读取,并使用所选的语言对按钮进行编辑

try{
        String FILENAME = "LangFile";
        FileInputStream fos = openFileInput(FILENAME);
        byte[] b = new byte[2];
        fos.read(b);
        fos.close();
        if(new String(b).equalsIgnoreCase("NL")){
            Tower.setText(classNamesDutch[0]);
            Puzzle.setText(classNamesDutch[1]);
            Mirror.setText(classNamesDutch[2]);
            Tangram.setText(classNamesDutch[3]);
            Frog.setText(classNamesDutch[4]);
        }
        if(new String(b).equalsIgnoreCase("GB")){
            Tower.setText(classNamesEnglish[0]);
            Puzzle.setText(classNamesEnglish[1]);
            Mirror.setText(classNamesEnglish[2]);
            Tangram.setText(classNamesEnglish[3]);
            Frog.setText(classNamesEnglish[4]);
        }
        if(new String(b).equalsIgnoreCase("FR")){
            Tower.setText(classNamesFrench[0]);
            Puzzle.setText(classNamesFrench[1]);
            Mirror.setText(classNamesFrench[2]);
            Tangram.setText(classNamesFrench[3]);
            Frog.setText(classNamesFrench[4]);
        }
    }catch (java.io.FileNotFoundException e) {
      } catch (IOException e) {
        e.printStackTrace();
    }
现在,这是我保存和读取数字的代码

public void Savefile(){
    int level=0;
    String data;
    try{
        String FILENAME = "TowerFile";
        FileInputStream fos = openFileInput(FILENAME);
        byte[] b = new byte[1];
        fos.read(b);
        fos.close();            
        if(new String(b).equalsIgnoreCase("1")){
            level=1;
        }
        if(new String(b).equalsIgnoreCase("2")){
            level=2;
        }
        if(new String(b).equalsIgnoreCase("3")){
            level=3;
        }
        if(new String(b).equalsIgnoreCase("4")){
            level=4;
        }
        if(new String(b).equalsIgnoreCase("5")){
            level=5;
        }
        if(level!=1 || level!=2 || level!=3 || level!=4 || level!=5){
            FILENAME="TowerFile";
            data="een";
            FileOutputStream fostemp = openFileOutput(FILENAME, Context.MODE_PRIVATE);
            fostemp.write(data.getBytes());
            fostemp.close();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
这就是我想读的方式

try{
        String FILENAME = "TowerFile";
        FileInputStream fos = openFileInput(FILENAME);
        byte[] b = new byte[1];
        fos.read(b);
        fos.close();
        if(new String(b).equalsIgnoreCase("1")){
            button1.setVisibility(Button.GONE);
        }
        if(new String(b).equalsIgnoreCase("2")){
            level=2;
        }
        if(new String(b).equalsIgnoreCase("3")){
            level=3;
        }
        if(new String(b).equalsIgnoreCase("4")){
            level=4;
        }
        if(new String(b).equalsIgnoreCase("5")){
            level=5;
        }
    }catch (java.io.FileNotFoundException e) {
    } catch (IOException e) {
            e.printStackTrace();
    }

所以我不知道你现在想用什么地方出了问题。这并不能解释为什么你必须这样做,我假设你有操作系统权限,但这应该对你有用。

Ow和我使用相同的方法处理两页之间的数字,所以我真的觉得奇怪,它不起作用。你是什么意思?我在哪里使用它?你可以在任何有上下文引用的地方使用它。我给你的链接就是一个例子。但是如果我使用youre行,我会得到错误,Context.MODE_PRIVATE我已经使用了。我只是试着在一场比赛后保存,程序会以wright的方式保存变量,只有在开始时,如果你想把一切都设置为1,它就会运行。