title: Writing and Reading Integer/String Array Values to File (Android Application Development)
body: <p>I am trying to write &amp; read integer arrays RED[] and BLUE[] to a file. I've tried converting them into strings and writing them, hoping that it would work, but no luck there. Am I on the right track? I've tried DataOutputStreams but that hasn't worked out for me either.</p>
  
  <p>As of now I'm certain that something isn't right since neither buttons are responsive. The program isn't going through either of the try{}.</p>
  
  <p><b>Writing onto File</b></p>
  
  <pre><code>bSave.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  String FILENAME = name.getText().toString();
  
                  try {
                      fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
                      BufferedWriter bw = new BufferedWriter(new FileWriter(FILENAME));
                      bw.write(Arrays.toString(paletteview.RED));
                      bw.write(Arrays.toString(paletteview.BLUE));
                      fos.close();
  
                  } catch (FileNotFoundException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
          });
  </code></pre>
  
  <p><b>Reading from File</b></p>
  
  <pre><code>listview.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                      int position, long id) {
                  String data=null;
                  String FILENAME = savedarray[position];
  
                  try {
                      String inputLine = null;
                      StringBuilder sb = null;
  
                      fis = openFileInput(FILENAME);
                      BufferedReader br = new BufferedReader(new FileReader(FILENAME));
                      while ((inputLine = br.readLine()) != null) {
                          sb.append(br.readLine());
                      }
                      fis.close();
                      data=sb.toString();
                      text.setText(data);
  
                  } catch (FileNotFoundException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
          });
  </code></pre>
  
  <p><b> Reading from File: Try #2 (Added textview to see what I read)</b></p>
  
  <pre><code>@Override
  public void onItemClick(AdapterView&lt;?&gt; parent, View view,
          int position, long id) {
      String data=null;
      String FILENAME = savedarray[position];
      File f = new File(FILENAME);
      if (f.exists) {
          textview.setText(FileManager.readFromFile(f));
      }
  }
  </code></pre>
  
  <p><b> Writing to File: Try #2 </b> (for intArrayToString Method, refer to below)</p>
  
  <pre><code>    @Override
      public void onClick(View v) {
          if (name.getText().toString() != null){
              FILENAME = name.getText().toString();
              File f = new File(FILENAME);
              FileManager.writeToFile(f, intArrayToString(paletteview.RED));
          }
      }
  </code></pre>
  
  <p><b> intArrayToString (used in Writing to File #2) </b></p>
  
  <pre><code>String intArrayToString(int[] array) {
      String text = "" + array[0];
      for (int i = 1; i &lt; array.length; i++) {
          text += ","+array[i];
      }
      return text;
  </code></pre>
  
  <p><b> * File Manager (copied from NoInspiration's answer) </b></p>