简体   繁体   English

从android sdcard文件中删除带有问号文本的黑色菱形

[英]remove black diamond with a question mark text from android sdcard file

I am creating a listview with json data.When user is offline I want to show the data in listview. 我正在使用json数据创建一个列表视图。当用户离线时,我想在列表视图中显示数据。 I have stored the json data in android sdcard. 我已经将json数据存储在android sdcard中。 And I retrive the data when user is offline and showed it in listview. 当用户处于脱机状态时,我会检索数据并将其显示在列表视图中。 The problem is, when I read the file from directory it's show's me black diamond with a question mark and stores it in array list. 问题是,当我从目录中读取文件时,它显示带有问号的黑色菱形并将其存储在数组列表中。 this type of " t *" my question is how to remove this type of string from Arraylist. 这种类型的“ t *”我的问题是如何从Arraylist中删除这种类型的字符串。 Someone please help 有人请帮忙

Save the Data: 保存数据:

 public  void saveMyData()
{
    try {
        ObjectOutput out = new ObjectOutputStream(new FileOutputStream(new File(getFilesDir(),"")+"cachefile.txt"));
        out.writeObject(al.toString());
        Toast.makeText(getApplicationContext(), "Data Saved..",Toast.LENGTH_LONG).show();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

This is my retrieving code. 这是我的检索代码。

String fileContent = "";
    try {
        String currentLine;
        BufferedReader bufferedReader;
        FileInputStream fileInputStream = new FileInputStream(getFilesDir()+"cachefile.txt");
        bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream,"UTF-8"));


        while ((currentLine = bufferedReader.readLine()) != null) {
            fileContent += currentLine + '\n';
        }

        bufferedReader.close();
    } catch (IOException e) {
        e.printStackTrace();

        Log.d("FAILED","THOS IS NULL");
        fileContent = null;
    }
    Log.d("SUCESS","SUCESS BUDDYY"+fileContent);

Broadly speaking, the issue is that you're using an ObjectOutputStream to write your data to the file, but a BufferedReader to read it back in. The ObjectOutputStream is specifically designed to allow objects and native data types to be written to a stream in a way they can be read back in via an ObjectInputStream to reconstitute the objects in the same way. 广义上讲,问题在于您使用的是ObjectOutputStream将数据写入文件,而使用BufferedReader读取回文件ObjectOutputStream专门用于允许将对象和本机数据类型写到文件中的流中。可以通过ObjectInputStream读回它们,以相同的方式重构对象。 This encoding is not meant to be human readable and usually contains extra characters as field separators. 这种编码不是人类可读的,通常包含额外的字符作为字段分隔符。

I don't know what al is, but since you're calling toString() before you write it, I can assume that you want actual strings in a file you can read. 我不知道是什么al的,但因为你调用toString()你写之前,我可以假设你想在你可以阅读文件的实际字符串。 To do this, you probably want to use a PrintStream and the PrintStream.println() method instead of the ObjectOutputStream . 为此,您可能要使用PrintStreamPrintStream.println()方法代替ObjectOutputStream

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM