title: how to save ArrayList into internal Storage
body: <p>I'm trying to make an inventory apps to save item by item into internal storage. Here is my layout. The problem is it possible to save arraylist into document text file / other internal storage? Because fos.write(listitem.getBytes()); should be in Int. Here is my code from Activity2</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>package com.example.java;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.Spinner;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.util.ArrayList;
  
  public class MainActivity2 extends AppCompatActivity {
      public static final String extraint = "1";
      public static final String namabarang = "2";
      public static final String jumlahstock ="3";
      public static final String FILE_NAME="example.txt";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main2);
  
          Intent intent = getIntent();
  
          Spinner spinner = (Spinner) findViewById(R.id.spinner);
  
          ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this,
                  R.array.planets_array, android.R.layout.simple_spinner_item);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner.setAdapter(adapter);
      }
  
      public void onBtnClick(View view){
  
  
          TextView plain1 = findViewById(R.id.NamaBarang);
          TextView plain2 = findViewById(R.id.SKU);
          TextView plain3 = findViewById(R.id.JumlahStok);
          TextView plain4 = findViewById(R.id.HargaBeli);
          TextView plain5 = findViewById(R.id.HargaJual);
          Intent intent = new Intent(this,MainActivity3.class);
          String x = "1";
  
          String text = plain1.getText().toString();
          FileOutputStream fos = null;
          Item m1 = new Item("a","1");
          Item m2 = new Item("b","2");
          Item m3 = new Item("c","3");
          ArrayList&lt;Item&gt; listitem =  new ArrayList&lt;&gt;();
  
          listitem.add(m1);
          listitem.add(m2);
          listitem.add(m3);
          try {
              fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
              fos.write(listitem.getBytes());
  
              Toast.makeText(this,"Saved to" +getFilesDir() + "/" + FILE_NAME,Toast.LENGTH_LONG).show();
          }catch(FileNotFoundException e){
              e.printStackTrace();
          }catch(IOException e){
              e.printStackTrace();
          }finally{
              if(fos != null){
                  try{
                      fos.close();
                  }catch(IOException e){
                      e.printStackTrace();
                  }
              }
          }
  
          intent.putExtra(extraint,x);
          intent.putExtra(FILE_NAME,text);
          intent.putExtra(namabarang,plain1.getText().toString());
          intent.putExtra(jumlahstock,plain3.getText().toString());
          startActivity(intent);
  
  
  
      }
  }</code></pre>
  </div>
  </div>
  
  Here is another code from Activity 3</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>package com.example.java;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.renderscript.ScriptGroup;
  import android.util.Log;
  import android.view.View;
  import android.widget.FrameLayout;
  import android.widget.ListView;
  
  import org.w3c.dom.Element;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.sql.Array;
  import java.util.ArrayList;
  import java.util.Arrays;
  
  
  public class MainActivity3 extends AppCompatActivity {
      private static final String Tag = "MainAcitivity3";
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main3);
          Log.d(Tag, "onCreate: Started.");
          ListView mListView = (ListView) findViewById(R.id.listView);
          Intent intent = getIntent();
  
          String[] barang = new String[20];
          String[] jumlah = new String[20];
          ArrayList&lt;Item&gt; itemlist = new ArrayList&lt;Item&gt;();
  
          int loop=0;
          barang[loop] = intent.getStringExtra(MainActivity2.namabarang);
          jumlah[loop] = intent.getStringExtra(MainActivity2.jumlahstock);
          loop++;
          FileInputStream fis = null;
          StringBuilder sb = new StringBuilder();
          try {
              fis = openFileInput(MainActivity2.FILE_NAME);
              InputStreamReader isr = new InputStreamReader(fis);
              BufferedReader br = new BufferedReader(isr);
              String text;
  
              while ((text = br.readLine()) != null){
                  sb.append(text).append("\n");
              }
  
  
          }catch(FileNotFoundException e){
              e.printStackTrace();
          }catch(IOException e){
              e.printStackTrace();
          }finally {
              if(fis!=null){
                  try{
                      fis.close();
                  }catch(IOException e){
                      e.printStackTrace();
                  }
              }
          }
          String result=sb.toString();
          for(int i=0;i&lt;loop;i++) {
              Item sparepart = new Item(result, result);
  
              itemlist.add(sparepart);
          }
          PersonListAdapter adapter = new PersonListAdapter(this, R.layout.adapter_view_layout,itemlist);
          mListView.setAdapter(adapter);
  
          String number = intent.getStringExtra(MainActivity2.extraint);
          if(number != null) {
              FrameLayout lay = (FrameLayout) findViewById(R.id.frames);
              if (number.equals("1")) {
                  lay.setVisibility(View.INVISIBLE);
                  mListView.setVisibility(View.VISIBLE);
              } else {
  
              }
          }
          else{}
  
      }
  
      public void onBtnClick (View view){
          Intent intent = new Intent(this,MainActivity2.class);
  
          startActivity(intent);
      }
  
  
  
  }</code></pre>
  </div>
  </div>
  </p>
  <p>The apps supposed to save one item by item into the internal storage which where i try to utilize array to save the into the internal storage, but it it possible to save and read array to internal storage?</p>