Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. converting file data to string

converting file data to string

Scheduled Pinned Locked Moved Java
question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 0 Offline
    0 Offline
    002comp
    wrote on last edited by
    #1

    Hello Friends I am reading a file Like this here is the code below:

        FileInputStream in = new FileInputStream(file);
        Reader r = new InputStreamReader(in, "ISO-8859-1");
        int intch;
        while ((intch = r.read()) != -1) {
    
          int temp = intch;
          
        }
    

    Previously I was putting all data into another file char by char like this

    OutputStream out = new FileOutputStream(outFilePath);
    and using out.write(temp); in while loop

    And it was working fine. But now The value coming in temp ,I want to store in a string.temp contains some int value of that charset and I want tht in string. Any Suggestions?? Thanks In Advance. Regards Yogesh

    0 1 Reply Last reply
    0
    • 0 002comp

      Hello Friends I am reading a file Like this here is the code below:

          FileInputStream in = new FileInputStream(file);
          Reader r = new InputStreamReader(in, "ISO-8859-1");
          int intch;
          while ((intch = r.read()) != -1) {
      
            int temp = intch;
            
          }
      

      Previously I was putting all data into another file char by char like this

      OutputStream out = new FileOutputStream(outFilePath);
      and using out.write(temp); in while loop

      And it was working fine. But now The value coming in temp ,I want to store in a string.temp contains some int value of that charset and I want tht in string. Any Suggestions?? Thanks In Advance. Regards Yogesh

      0 Offline
      0 Offline
      002comp
      wrote on last edited by
      #2

      Or Is there any way to read file line by line thru BufferedReader whose data is in ISO-8859-1 charset. I tried like this even

      this(new BufferedReader(new InputStreamReader(new FileInputStream(file),"ISO-8859-1")));

      but bufferedReader is coming null. Any Ideas?? Regards Yogesh

      J 1 Reply Last reply
      0
      • 0 002comp

        Or Is there any way to read file line by line thru BufferedReader whose data is in ISO-8859-1 charset. I tried like this even

        this(new BufferedReader(new InputStreamReader(new FileInputStream(file),"ISO-8859-1")));

        but bufferedReader is coming null. Any Ideas?? Regards Yogesh

        J Offline
        J Offline
        jwhite9 0
        wrote on last edited by
        #3

        I'm kind of new to this whole Java thing but there is a readLine() method on BufferedReader. How about something like this? ISO-8859 is a standard 8 bit character encoding so you shouldn't have problems reading the file. String line; BufferedReader br = new BufferedReader(new FileReader(fileName)); while ((line = br.readLine()) != null) { // do stuff with line } br.close();

        0 1 Reply Last reply
        0
        • J jwhite9 0

          I'm kind of new to this whole Java thing but there is a readLine() method on BufferedReader. How about something like this? ISO-8859 is a standard 8 bit character encoding so you shouldn't have problems reading the file. String line; BufferedReader br = new BufferedReader(new FileReader(fileName)); while ((line = br.readLine()) != null) { // do stuff with line } br.close();

          0 Offline
          0 Offline
          002comp
          wrote on last edited by
          #4

          I already Tried like this but bufferedReader is coming null. And moreover it would be better if somebody suggest how can I convert each ISO-8859-1 character into String Bcoz I have to do some decoding for each character. Thanks Yogesh

          D 1 Reply Last reply
          0
          • 0 002comp

            I already Tried like this but bufferedReader is coming null. And moreover it would be better if somebody suggest how can I convert each ISO-8859-1 character into String Bcoz I have to do some decoding for each character. Thanks Yogesh

            D Offline
            D Offline
            David Skelly
            wrote on last edited by
            #5

            What do you mean "bufferedReader is coming null"? If I do this:

            BufferedReader br = new BufferedReader(new FileReader(fileName));

            then either I will get a BufferedReader created or I will get a FileNotFoundException. I can't quite see how you are getting a null here. If file encoding is a problem for you then use InputStreamReader: http://java.sun.com/docs/books/tutorial/i18n/text/stream.html[^]

            0 1 Reply Last reply
            0
            • D David Skelly

              What do you mean "bufferedReader is coming null"? If I do this:

              BufferedReader br = new BufferedReader(new FileReader(fileName));

              then either I will get a BufferedReader created or I will get a FileNotFoundException. I can't quite see how you are getting a null here. If file encoding is a problem for you then use InputStreamReader: http://java.sun.com/docs/books/tutorial/i18n/text/stream.html[^]

              0 Offline
              0 Offline
              002comp
              wrote on last edited by
              #6

              Thx a Lot David.Tht link is very helpful and solves my prob. And actually bufferedReader.readLine is coming null tht i just forget to write. Anyway,Thx again. Regards Yogesh

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups