我有點新來用java編程和一切,並看到有沒有人可以幫助我這個。我試圖做到這一點,以便它可以保存一個文件,然後能夠打開它,但我不能嘗試和運行的應用程序,因爲紅線。任何人都可以幫我用正確的代碼去?由於使用EditText方法和它可以做什麼
'public class Documents extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.documents);
EditText txtView=(EditText)findViewById(R.id.textbox);
}
public void saveClicked(View v) {
try {
OutputStreamWriter out =
new OutputStreamWriter(openFileOutput(STORETEXT, 0));
out.write(EditText.gettext.toString());
out.close();
Toast.makeText(this, "The contents are saved in the file.", Toast.LENGTH_LONG).show();
}catch (Throwable t) {
Toast.makeText(this, "Exception: "+t.toString(), Toast.LENGTH_LONG).show();
}
}
private final static String STORETEXT="storetext.txt";
public void readFileInEditor(){
try{
InputStream in=openFileInput(STORETEXT);
if (in !=null){
InputStreamReader tmp=new InputStreamReader(in);
BufferedReader reader=new BufferedReader(tmp);
String str;
StringBuilder buf=new StringBuilder();
while ((str=reader.readLine()) !=null){
buf.append(str+"n");
}
in.close();
EditText.setText(buf.toString());
}
}catch (FileNotFoundException e) {
// that's OK, we probably haven't created it yet
}catch (Throwable t){
Toast.makeText(this, "Exception: "+t.toString(), Toast.LENGTH_LONG).show();
}
}'
}
嘗試調試或打印變量以查看代碼中的哪個點停止執行它應該執行的操作。 – 2015-02-11 20:11:00
你有什麼問題? – JNYRanger 2015-02-11 20:11:48
他正在嘗試使用他的應用程序並將數據保存到文本文件,並使用該應用程序從文本文件中讀取 – 2015-02-11 20:15:04