Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android如何使用内部存储读取数据_Android_Save_Storage_Internal - Fatal编程技术网

android如何使用内部存储读取数据

android如何使用内部存储读取数据,android,save,storage,internal,Android,Save,Storage,Internal,我的程序在尝试执行fis.readtempread.getBytes时崩溃 我想读取data.gds中的第一行并将其放入一个字符串中,如何才能做到这一点? 不,我不打算使用SharedReferences添加一个字符串缓冲区,然后从中读取每个行都将放入Stringbuffer中,然后您可以从该缓冲区中检索该行 public void loadprev() { String tempread; try { FileInputStream fis = openF

我的程序在尝试执行fis.readtempread.getBytes时崩溃

我想读取data.gds中的第一行并将其放入一个字符串中,如何才能做到这一点?
不,我不打算使用SharedReferences添加一个字符串缓冲区,然后从中读取每个行都将放入Stringbuffer中,然后您可以从该缓冲区中检索该行

public void loadprev()
{
       String tempread;
    try {
        FileInputStream fis = openFileInput("data.gds");

        try {
            fis.read(tempread.getBytes());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            fis.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

}
此外,如果您没有正确捕获异常,请将其包围在1 try catch中,但以后尝试捕获它们:

StringBuffer fileContent = new StringBuffer("");
byte[] buffer = new byte[1024];

while ((n = fis.read(buffer)) != -1) 
{ 
  fileContent.append(new String(buffer, 0, n)); 
}
现在,您的代码更易于阅读。

也许这会有所帮助?
{
    String tempread;
 try {
    FileInputStream fis = openFileInput("data.gds");
        fis.read(tempread.getBytes());
        fis.close();
   } catch (FileNotFoundException e) {
        e.printStackTrace();
   }
     catch (IOException e) {
        e.printStackTrace();
       }

}