I want to get text print file from a text. Therefore, when a user enters the message and presses the submit button, the message is written in the file.
Here is my code:
package com.getText.android; Import java.io.buffferedWriter; Import java.io.file; Import java.io.filewiter; Import java.io.IOException; Import android App Importroid.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 getText activity expansion (public editText ET; public button 1; public string input; / ** activity was called upon for the first time. * / @Override public void OnCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.main); ET = (editable text) Khojwubiaiaidi (Araid. Aditekt); ET.setImeOptions (EditorInfo.IME_FLAG_NO_EXTRACT_UI); button 1 = (button) searching for Vibiaiaidi (on Arkdkbitianklik); Buttonl. SetOnClickListener (btnListener);} Private Onclick Lester BTNL Isnr = new Lestonr onclick () {public on zero (see V) {input = ET .get text (). ToString (); {File = new File (Environment .getExternalStorageDirectory (), "fileOut.txt") Try; BufferedWriter writer = new BufferedWriter (new FileWriter (file, true)); Writerkwrite (input); writer.newLine (); writer.flush (); writer.close ();} catch (IOException e) {E.printStackTrace ();}}}}} This application runs correctly, but the file is not created! Can anyone tell me what is wrong? :)
I'm not sure that it is necessary, but you tried to do this: < / P>
file.createNewFile (); Before creating FileWriter ? In general, you should try to log in with your exceptions:
logs. E ("gettext", e.getMessage ()); Unfortunately, e.printStackTrace () will not be made in lockback.
Comments
Post a Comment