我正在尝试制作的软件的问题是这样的;当我保存信息时,它与以下代码一起保存:
这样,信息以文本形式保存在 SD 中,但我无法读取该信息。我尝试了几种方法。
我想将 TXT 的内容保存在 String 中以将其放入 TextView。
try
{
String myData ;
FileInputStream fis = new FileInputStream(your file name);
DataInputStream in = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
myData = myData + strLine;
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
// play with myData..It's file content
I have tried this code and it works perfectly :D
文件 ruta_sd = Environment.getExternalStorageDirectory(); 文件 f = new File(ruta_sd.getAbsolutePath(), "datos.txt");
BufferedReader fin =new BufferedReader( new InputStreamReader( new FileInputStream(f))); String texto = fin.readLine(); fin.close(); textohere.setText(texto);