0

我必须将从 EditTex 获取的文本文件保存到内部存储中。一切正常,但如果我在 EditText 中写入欧元 € 的货币符号并将其保存到内部存储中,当我恢复文件并将其放入 TextView 时,欧元的符号将转换为: ⬠这不会发生带有美元符号 $。下面是用于将文本文件保存到/从内部存储中检索的两种方法。请,任何建议如何保持正确的欧元符号?

private void store (String filename, String data)
{
    try
    {
        FileOutputStream fOut= openFileOutput(filename,MODE_PRIVATE);
        fOut.write(data.getBytes());
        fOut.close();

    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }


private String read(String namefile, String datxt)
{
    try{
        FileInputStream fin=openFileInput(namefile);
        int c;
        String temp="";
        while ((c=fin.read())!=-1)
        {
            temp=temp+Character.toString(((char)c));
        }
        datxt=temp;
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    return datxt;
}
4

1 回答 1

0

我有同样的问题,这就是我所做的。如果此解决方案解决了您的问题,请将此答案标记为已接受。

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public String UTF8 = "utf8";
public int BUFFER_SIZE = 8192;

private void store (String filename, String data)
{
    try {
        BufferedWriter fOut = new BufferedWriter(new OutputStreamWriter(openFileOutput(filename, MODE_PRIVATE), UTF8), BUFFER_SIZE);
        fOut.write(data);
        fOut.close();
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
}

private String read(String namefile, String datxt)
{
    try {
        BufferedReader fin = new BufferedReader(new InputStreamReader(openFileInput(namefile), UTF8), BUFFER_SIZE);
        int c;
        String temp = "";
        while ((c = fin.read()) != -1) {
            temp = temp + Character.toString((char) c);
        }
        datxt = temp;
        fin.close();
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    return datxt;
}
于 2015-02-27T09:10:46.623 回答