title: How to write and read text in txt file from internal storage of android vitual
body: <p>i am learning by myself, without training in school.
  i need yours help, because i got a stuff and founding all question in the website but i can not solve it.
  it's very simple with you i think that. i also knew i get the wrong path(connect link).</p>
  <p>this's my code below</p>
  <p>Please help me find the path for internal storage.
  i am using genymothion with android 9 API 28.
  and Amaze file manager.</p>
  <p>'enter code here'
  Activity main:</p>
  <pre><code>    &lt;Button
          android:id=&quot;@+id/btnwrite&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginTop=&quot;26dp&quot;
          android:text=&quot;WRITE&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/edtnhap&quot; /&gt;
  
      &lt;EditText
          android:id=&quot;@+id/edtnhap&quot;
          android:layout_width=&quot;366dp&quot;
          android:layout_height=&quot;48dp&quot;
          android:layout_marginStart=&quot;10dp&quot;
          android:layout_marginTop=&quot;10dp&quot;
          android:layout_marginEnd=&quot;10dp&quot;
          android:ems=&quot;10&quot;
          android:hint=&quot;Nhập dữ liệu tại đây&quot;
          android:inputType=&quot;textPersonName&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
      &lt;Button
          android:id=&quot;@+id/btndoc&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginStart=&quot;162dp&quot;
          android:layout_marginTop=&quot;30dp&quot;
          android:layout_marginEnd=&quot;161dp&quot;
          android:text=&quot;READ&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/btnwrite&quot; /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/tvdocdulieu&quot;
          android:layout_width=&quot;395dp&quot;
          android:layout_height=&quot;363dp&quot;
          android:layout_marginTop=&quot;27dp&quot;
          android:text=&quot;TextView&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/btndoc&quot; /&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  '''
  '''
  MainActivity
  public class MainActivity extends AppCompatActivity implements View.OnClickListener{
      private static final String INTERNAL_PATH = Environment.getDataDirectory().getPath()+&quot;/sdcard/&quot;;
      private static final String ACCOUNT_FILE = &quot;WRITING AND READ TESTING.txt&quot;;
  
      Button doc,ghi;
      EditText nhap;
      TextView hienthi;
  
      Boolean w;
  
  
  
  
      @Override
      protected void onCreate( Bundle savedInstanceState ) {
          super.onCreate( savedInstanceState );
          setContentView( R.layout.activity_main );
          init();
      }
  
      public void init(){
          doc = findViewById( R.id.btndoc );
          ghi = findViewById( R.id.btnwrite );
          nhap = findViewById( R.id.edtnhap );
          hienthi = findViewById( R.id.tvdocdulieu );
  
          doc.setOnClickListener( this);
          ghi.setOnClickListener( this );
      }
      @Override
      public void onClick( View v ) {
          switch (v.getId()){
              case R.id.btnwrite:
                      xulyviet();
                  break;
              case R.id.btndoc:
                  xulydoc();
  
                  break;
          }
      }
      private void xulyviet() {
          try {
              String path = INTERNAL_PATH + ACCOUNT_FILE;
  
              File file = new File( path );
  
              if(!file.exists()) {
                  w = file.createNewFile();
              }
              FileOutputStream fileOutputStream = new FileOutputStream( file, true );
              OutputStreamWriter outputStreamWriter = new OutputStreamWriter( fileOutputStream, &quot;UTF-8&quot; ); 
              outputStreamWriter.append( nhap.getText() );
              outputStreamWriter.close();
              fileOutputStream.close();
              Toast.makeText( MainActivity.this, &quot;đã nhập&quot;, Toast.LENGTH_SHORT ).show();
          } catch (IOException e) {
              e.printStackTrace();
              Toast.makeText( this, &quot;Không thể ghi&quot;, Toast.LENGTH_SHORT ).show();
          }
      }
      public void xulydoc(){
      }
  }
  </code></pre>
  <p><code>enter code here</code></p>