gpt4 book ai didi

java - android.content.res.Resources$NotFoundException

转载 作者:行者123 更新时间:2023-12-02 05:45:11 25 4
gpt4 key购买 nike

嘿,我在从 txt 文件加载数据时遇到问题

private void read() {


try {
// open the file for reading
InputStream instream = openFileInput(File.separator + "bla.txt");


// if file the available for reading
if (instream.available() >0) {
// prepare the file for reading
InputStreamReader inputreader = new InputStreamReader(instream);
BufferedReader buffreader = new BufferedReader(inputreader);

String line;

// read every line of the file into the line-variable, on line at the time
while (( line = buffreader.readLine()) != null) {
for(int i= 0; i<=1; i++){
if(i == 0){
bla = Integer.parseInt(buffreader.readLine());
}
if(i == 1){
bla2 = Integer.parseInt(buffreader.readLine());
}


}

// close the file again
instream.close();


Toast.makeText(getBaseContext(),
"Ladevorgang war efolgreich!",

Toast.LENGTH_LONG).show();

}}
}

catch (java.io.FileNotFoundException e) {
Toast.makeText(getBaseContext(),
"Datei nicht vorhanden",

Toast.LENGTH_LONG).show();
}
catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();

请帮助我,我不知道我应该改变什么:(我总是得到 android.content.res.Resources$NotFoundException: String Resource ID #0x0感谢 Strik3r 的帮助

private  void save() {

try {

File myFile = new File(Environment.getExternalStorageDirectory() + File.separator + "bla.txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter =
new OutputStreamWriter(fOut);
myOutWriter.append(string.toString() + "\n");
myOutWriter.append(string2.toString());

myOutWriter.close();
fOut.close();
Toast.makeText(getBaseContext(),
"Gespeichert",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}

这是保存的数据

最佳答案

 // open the file for reading

InputStream instream = openFileInput(File.separator + "bla.txt");

似乎不是一个有效的文件。相反,请尝试

InputStream instream = openFileInput(Environment.getExternalStorageDirectory() +File.separator + "bla.txt");

关于java - android.content.res.Resources$NotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24138467/

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