1

I am using following code to write json to my local path which i get from my html page.Again I have to construct a html page by reading content from the saved local json file.For this I have to read this saved file from local which is plain text and give as input to java file. I got confused whether to use Buffered Reader or BufferedInputStream to read that file from local path.Please help me.

java.io.BufferedWriter jsonOut = new java.io.BufferedWriter(
    new java.io.OutputStreamWriter(
        new java.io.FileOutputStream(uploadDir +
            _req.getParameter("filename")), "ISO-8859-1"));

3 Answers 3

1

BufferedReader for text.

Reason: http://tutorials.jenkov.com/java-io/bufferedreader.html

0

You can use BufferedReader for text but you should ensure to use the proper charset in your case (otherwise it defaults to the platform charset)

BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(myFile),"ISO-8859-1"));
0

To read a file you can use the following code

 File f = new File("your json file");
  BufferedReader buf = new BufferedReader(new FileReader(f));
  String line = null;

   while ((line = buf.readLine()) != null) {

    System.out.println("json file line " + line); 
   // do your changes
   }

Not the answer you're looking for? Browse other questions tagged or ask your own question.