【问题标题】:how to use internal Storage in DatabaseHelper?如何在 DatabaseHelper 中使用内部存储?
【发布时间】:2015-04-27 21:43:52
【问题描述】:

我想在数据库助手中使用内部存储 (opennFileOutput)。 这是我的代码:

public class DBDAO {
    protected SQLiteDatabase database;
    private DatabaseHelper dbHelper;
    private Context mContext;

    public DBDAO(Context context) {
        this.mContext = context;
        dbHelper = new DatabaseHelper(mContext);
    }
    public void WriteFile(String writeString) {
        // add-write text into file
        try {
            FileOutputStream fileout = openFileOutput("language.txt", MODE_PRIVATE);
            OutputStreamWriter outputWriter = new OutputStreamWriter(fileout);
            outputWriter.write(writeString);
            outputWriter.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
// Read text from file
    public String ReadFile() {
        // reading text from file
        String s = "";
        try {
            FileInputStream fileIn = openFileInput("language.txt");
            InputStreamReader InputRead = new InputStreamReader(fileIn);
            char[] inputBuffer = new char[100];
            int charRead;
            while ((charRead = InputRead.read(inputBuffer)) > 0) {
                // char to string conversion
                String readstring = String
                        .copyValueOf(inputBuffer, 0, charRead);
                s += readstring;
            }
            InputRead.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return s;
    }
}

但是,出现以下错误:OpenFileOutput : MODE_PRIVATE 无法解析为变量

并且:方法 openFileInput(String) 没有为 DBDAO 类型定义

那么有人可以告诉我如何解决它吗?

非常感谢,对不起,因为我的英语。

【问题讨论】:

    标签: android sqlite file


    【解决方案1】:

    openFileInput()openFileOutput()MODE_PRIVATE 等在Context 上定义。使用mContext.openFileInput()mContext.openFileOutput()Context.MODE_PRIVATE

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多