EditText保存到文件,但没有创建文件!

时间:2011-05-13 13:38:20

标签: java android file text android-edittext

package com.russell.saw;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;

public class notetaker extends Activity {
    public EditText edittext;
    public Button save;
    public String input;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notetaker);
        edittext = (EditText) findViewById(R.id.edittext);
        edittext.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); 
        save = (Button)findViewById(R.id.save);
        save.setOnClickListener(btnListener);
    }
    private OnClickListener btnListener = new OnClickListener() {
        public void onClick(View v) {
            input = edittext.getText().toString(); 
            File file = new File(Environment.getExternalStorageDirectory(), "fileOut.txt");
            try{
                BufferedWriter writer = new BufferedWriter(new FileWriter(file,true));
                writer.write(input);
                writer.newLine();
                writer.flush();
                writer.close();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

当我点击使用此代码保存时,我没有收到任何文件,任何人都知道我哪里出错了。

(警告:我对Android非常陌生,所以请不要吝啬,如果它显而易见:3)

0 个答案:

没有答案