如何在DatabaseHelper中使用内部存储?

时间:2015-04-27 13:38:43

标签: android sqlite file

我想在数据库帮助器中使用内部存储(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无法解析为变量

和:未定义类型DBDAO的方法openFileInput(String)

所以有人可以告诉我如何解决它?

非常感谢,抱歉,因为我的英语。

1 个答案:

答案 0 :(得分:0)

{p> int row_idx = 0, col_idx = 1; printf("\nTOP X: %04d", (*pas_test)[row_idx][col_idx].i4_x ); openFileInput()openFileOutput()等在MODE_PRIVATE上定义。使用ContextmContext.openFileInput()mContext.openFileOutput()