EditText saving to file, but no file created!
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();开发者_C百科
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
I'm not getting any file come up when i click save with this code, anyone know where i'm going wrong .
(warning: i am VERY new to android, so please don't be mean if it's blindingly obvious :3)
精彩评论