8 Replies Latest reply: Feb 18, 2007 2:16 PM by 800282 RSS

    Write text file to  string?

    807606
      Could anyone tell me how to write a text file into a String with the text file created yet .
        • 1. Re: Write text file to  string?
          807606
          Do you mean read a text file into a String? Take a look at the Scanner class.
          • 2. Re: Write text file to  string?
            807606
            Sorry, I mean read a text file into a String.Thanks!
            • 3. Re: Write text file to  string?
              807606
              Have a look at this and see what you can understand. It's an old code which i wrote when i was learning java. I don't think i have used any coding conventions(I haven't given it a peep now).
              import java.io.*;
              
              class io6
              {
                   public static void main(String args[]) throws Exception
                   {
                        BufferedReader br=new BufferedReader(new FileReader("G:/java files/io5.java"));
                        String str=null;
                        while((str=br.readLine())!=null)
                        {
                             System.out.println(str);
                             Thread.sleep(75);
                        }
                   }
              }     
                        
              • 4. Re: Write text file to  string?
                800282
                ... I don't think i have used any coding
                conventions(I haven't given it a peep now).
                You should do so (for your own benefit and your project-colleagues):
                http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
                • 5. Re: Write text file to  string?
                  807606
                  ... I don't think i have used any coding
                  conventions(I haven't given it a peep now).
                  You should do so (for your own benefit and your
                  project-colleagues):
                  http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc
                  .html
                  I won't be needing this. That was a long time back. Then i never knew what were the coding conventions. And the example i produced was when i was still learning java(didn't know what were the coding conventions then) and the same example i have picked and posted. There's a difference between now and then both in terms of time and what i have learnt and coding conventions is one thing that i learnt.
                  • 6. Re: Write text file to  string?
                    800282
                    ...
                    I won't be needing this. That was a long time back.
                    Then i never knew what were the coding conventions.
                    And the example i produced was when i was still
                    learning java(didn't know what were the coding
                    conventions then) and the same example i have picked
                    and posted. There's a difference between now and then
                    both in terms of time and what i have learnt and
                    coding conventions is one thing that i learnt.
                    Then try to assist the OP by posting code that is consistent with Java's code conventions.
                    • 7. Re: Write text file to  string?
                      807606
                      Then try to assist the OP by posting code that is
                      consistent with Java's code conventions.
                      I was a bit lazy to edit the names and post and thats the reason why i told him that i haven't used coding conventions in that code. The op anyways wants to know how to carry out the task and the code should give him/her the direction needed.
                      • 8. Re: Write text file to  string?
                        800282
                        I was a bit lazy
                        ...
                        Then we agree on something after all!