title: Reading and writing String files with JSON in java
body: <p>I want to read a text file and process it's data.so for example the input file will look like :</p>
  
  <pre><code>john,judd,134
  Kaufman,kim,345
  </code></pre>
  
  <p>then the program should parse and store these data in form of a JSON file so it will be organized for further processing.I'm using <a href="https://code.google.com/p/json-simple/" rel="nofollow">JSON-simple</a> for this task .and this is a prototype code I've written:</p>
  
  <pre><code>package com.company;
  
  import org.json.simple.JSONObject;
  
  import java.io.*;
  
  public class Main {
  
  
  static JSONObject jsonObject = new JSONObject();
  static String output;
  
  public static void main(String[] args) throws IOException {
  
      read("/Users/Sepehr/Desktop/JSONexample.txt");
      write("/Users/Sepehr/Desktop/JSONexampleout,txt");
  
  }
  
  public static String read(String filenameIn) throws IOException {
  
      BufferedReader bufferedReader = new BufferedReader(new FileReader(filenameIn));
      String s ;
  
      while ( (s = bufferedReader.readLine() ) != null)
  
      {
          String[] stringsArr = s.split(",");
  
  
          jsonObject.put( "famname" , stringsArr[0] );
          jsonObject.put("name" , stringsArr[1]);
          jsonObject.put("id", stringsArr[2]);
  
          bufferedReader.close();
  
  
      }
  
      return output=jsonObject.toJSONString();
  
  
  }
  
  
  public static String write(String filenameOut) throws FileNotFoundException {
  
      PrintWriter printWriter = new PrintWriter(filenameOut);
      printWriter.write(jsonObject.toJSONString());
      printWriter.close();
  
      String se = "yaaayyy :|";
      return se;
  
  }
  
  
  
  }
  </code></pre>
  
  <p>after running the program these are the exceptions I get:</p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Stream closed
  at java.io.BufferedReader.ensureOpen(BufferedReader.java:97)
  at java.io.BufferedReader.readLine(BufferedReader.java:292)
  at java.io.BufferedReader.readLine(BufferedReader.java:362)
  at com.company.Main.read(Main.java:30)
  at com.company.Main.main(Main.java:18)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  </code></pre>
  
  <p>what is wrong exactly ? </p>
  
  <p>and how should make a better design for this program ?</p>