gpt4 book ai didi

android - 使用文件 : read and write many times

转载 作者:行者123 更新时间:2023-11-29 21:50:22 24 4
gpt4 key购买 nike

我是 Android 开发的新手,我不知道文件是怎么回事。

那是关于音频信息。

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

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

最佳答案

是的,你已经再次阅读了文件假设您使用文本文件来保存数据。例如。

我是这样保存的

    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();
}

关于android - 使用文件 : read and write many times,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14557539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com