title: Add new element in a file
body: <p>mycode:    </p>
  
  <pre><code>try {
          FileInputStream inputStream1 = getActivity().openFileInput("filename");
          BufferedReader b = new BufferedReader(new InputStreamReader(inputStream1));
          StringBuilder total = new StringBuilder();
          String line;
          while ((line = b.readLine()) != null) {total.append(line);}
          b.close();
          inputStream1.close();
  
      String json = total.toString();
  
      Items oldItems = new Gson().fromJson(json,Items.class);
      Items newItem = new Items();
      newItem.setName(example.getName());
      List&lt;Items&gt; items = new ArrayList&lt;Items&gt;();
      items.add(oldItems);
      items.add(newItem);
      Gson gson = new Gson();
      String itemsJson = gson.toJson(items);
  
      try {
          FileOutputStream outputStream =  getActivity().openFileOutput("filename", getActivity().MODE_PRIVATE);
          outputStream.write(itemsJson.getBytes());
          outputStream.close();
      } catch (Exception e) {
          e.printStackTrace();
      }
  
  } catch (Exception e) {
      e.printStackTrace();
      try {
          Items newItem = new Items();
          newItem.setItem(example.getName());
          Gson gson = new Gson();
          String json = gson.toJson(newItem);
          FileOutputStream outputStream =  getActivity().openFileOutput("filename", getActivity().MODE_PRIVATE);
          outputStream.write(json.getBytes());
          outputStream.close();
      } catch (Exception d) {
          d.printStackTrace();
      }
  }
  </code></pre>
  
  <p>I'm trying to write a code that read and write json in a file. I have no problem writing this:</p>
  
  <pre><code>[{"name":"a"},{"name":"b"}]
  </code></pre>
  
  <p>but when i try to read it for add a new "item" i have an error.
  My idea is to add a new item when I click the button.
  I don't understand what is the problem and how i can fix this problem. </p>
  
  <p>Items.java</p>
  
  <pre><code>class Items implements Serializable {
      @SerializedName("name")
      @Expose
      private String name;
  
  public String getName() { return name;}
  
  public void setName(String name) {
      this.name = name;
  }
  
  }
  </code></pre>
  
  <p>EDIT
  The error is this:</p>
  
  <blockquote>
    <p>com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:
    Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $</p>
  </blockquote>