通过单击按钮从编辑文本中写入文件中的数据块

时间:2012-12-12 04:25:00

标签: android android-intent

Hii我是Android开发的新手,我正在尝试这个简单的应用程序,我的问题是 我正在尝试通过单击按钮将编辑文本中的数据块保存到文件中 但我无法这样做! 我的代码块是

 saveBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        String str = textBox.getText().toString();

        try
        {

            FileOutputStream fOut =
            openFileOutput("textfile.txt", MODE_WORLD_READABLE); 
            OutputStreamWriter osw = new OutputStreamWriter(fOut);


            osw.write();
            osw.flush();
            osw.close();


            Toast.makeText(getBaseContext(), "File saved successfully!", Toast.LENGTH_SHORT).show();


            Toast.makeText(getBaseContext(), "file path" + getFileStreamPath ("textfile.txt"), Toast.LENGTH_LONG).show(); 
            textBox.setText("");
        }

        catch (IOException ioe) 
        {
            ioe.printStackTrace();
        }

1 个答案:

答案 0 :(得分:0)

您无法执行此操作,因为您未传递Str值 即String str = textBox.getText()。toString();

to: - osw.write(); 就像我做完了

osw.write(STR);

这将解决您已经测试过的问题

了解更多此类资源,请查看以下网站

http://www.suvenconsultants.com/