1

我是 Android 开发的新手,我不知道这与文件有关。

那是关于音频信息的。

因此,如果我创建新文件并写入其中,则在它之后我会从该文件中读取。和新的迭代:我不创建新文件(因为我已经有了这个文件),并写入这个文件。现在我要从文件中读取(第二次写入后)我可以从文件中获取吗?

我需要获得第二份书面信息,我可以通过这种方式获得吗?

4

1 回答 1

2

是的,您再次阅读了该文件,假设您使用文本文件来保存数据。前任。

这就是我保存它的方式

    File temf=new File(getCacheDir()+"/data/mytext.txt");
    Writer out=null;
    if(temf.exists()){
        temf.delete();
    }
    try {
        out = new BufferedWriter(new FileWriter(temf));
        out.write("sample text") + "\r\n");
        }
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

这就是我检索它的方式

    FileInputStream fs;
    try {
        File temf=new File(getCacheDir()+"/data/mytext.txt");
        if (temf.exists()) {
            fs = new FileInputStream(temf);
            DataInputStream dis = new DataInputStream(fs);
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    dis));
            String str=br.readLine();
            while(str!=null)
            {
            if(str=="text you want to compare"){
              break;
             }else{
              str=br.readLine();
             }
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
于 2013-01-28T08:11:36.727 回答