如果保存和检索内部存储器,则欧元货币符号会发生变化

时间:2014-12-05 15:40:52

标签: java android internal-storage

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

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;
}

1 个答案:

答案 0 :(得分: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;
}