【发布时间】:2021-04-02 17:30:06
【问题描述】:
所以我试图将数据存储到我的内部存储并取回它,所以当我尝试取回数据时它会检索数据但是当我在条件语句中使用它时它不起作用
所以这些是存储和检索数据的方法
储存方法
// storing the credentials into the internal storage method
public void savedata(String FIlename, String datatobeStored) {
FileOutputStream fos = null;
try {
// storing at the parameter fileLocation
fos = openFileOutput(FIlename, MODE_PRIVATE);
// storint the parameter text Given
fos.write(datatobeStored.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
检索方法
// Retreiving the credentials from the the internal storage meathod
public String dataRetreive(String filename) {
String variableTogetStored = "qqq";
FileInputStream fis = null;
try {
fis = openFileInput(filename);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String text;
while ((text = br.readLine()) != null) {
sb.append(text).append("\n");
}
// retreiving the value from the storage and assigning it to the local variable
variableTogetStored = sb.toString();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// returing the local variable
return variableTogetStored;
}
当我尝试检索和调节语句时它不起作用
存储数据
savedata("teacherAdmin", "dashboardToTeachersAdmin");
检索数据
String fromwheressss = dataRetreive("teacherAdmin");
条件语句
if (fromwheressss.equals("dashboardToTeachersAdmin")) {
Toast.makeText(teacher_admin.this,
"Matched", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(teacher_admin.this,
"Not Matched", Toast.LENGTH_SHORT).show();
}
这个条件给了我不匹配*
即使我尝试将检索到的字段打印到 Toast,它也会打印出有点奇怪,下面有完整的空间
【问题讨论】:
标签: java android internal-storage