Reading .txt files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • slickn_sly

    #1

    Reading .txt files

    How do you read a .txt file and have the compiler print out what's in
    the text file?
    *---------------------------------*
    Posted at: http://www.GroupSrv.com
    Check: http://www.HotCodecs.com
    *---------------------------------*
  • anonymous

    #2
    Re: Reading .txt files

    slickn_sly wrote:[color=blue]
    > How do you read a .txt file and have the compiler print out what's in
    > the text file?
    > *---------------------------------*
    > Posted at: http://www.GroupSrv.com
    > Check: http://www.HotCodecs.com
    > *---------------------------------*[/color]

    http://java.sun.com/docs/books/tutor.../io/index.html

    The compiler does not print out the file, your program does.

    Comment

    • Gordon Beaton

      #3
      Re: Reading .txt files

      On Sun, 30 Jan 2005 11:28:40 +0100, anonymous wrote:[color=blue]
      > The compiler does not print out the file, your program does.[/color]

      Unless of course your program *is* a compiler...

      /gordon

      --
      [ do not email me copies of your followups ]
      g o r d o n + n e w s @ b a l d e r 1 3 . s e

      Comment

      • slickn_sly

        #4
        Re: Reading .txt files

        > anonymouswrote:
        slickn_sly wrote:[color=blue]
        > How do you read a .txt file and have the compiler print out what's[/color]
        in[color=blue]
        > the text file?
        > *---------------------------------*
        > Posted at: http://www.GroupSrv.com
        > Check: http://www.HotCodecs.com
        > *---------------------------------*
        >[/color]
        http://java.sun.com/docs/books/tutor.../io/index.html

        The compiler does not print out the file, your program
        does.[/quote:af0243bd4 5]


        oops...Any idea on how may i go about taking that input.txt file and
        using insertion sort to sort it?
        *---------------------------------*
        Posted at: http://www.GroupSrv.com
        Check: http://www.HotCodecs.com
        *---------------------------------*

        Comment

        • Sharp

          #5
          Re: Reading .txt files

          [color=blue]
          > How do you read a .txt file and have the compiler print out what's in
          > the text file?[/color]

          The Java compiler simply takes your source code and converts it into byte
          code, which may then by executed by an interpreter, such as the Java Virtual
          Machine (JVM). The JVM takes 'chunks' of byte code at a time and converts
          into native code and then executes it.

          Text files are commonly read using the FileReader Class.

          FileReader fr = new FileReader("MyF ile.txt");
          BufferedReader br = new BufferedReader( fr);
          String line = br.readLine();
          While (line !=null)
          {
          System.out.prin tln(line);
          line = br.readLine();
          }

          Cheers
          Michael






          ---
          Outgoing mail is certified Virus Free.
          Checked by AVG anti-virus system (http://www.grisoft.com).
          Version: 6.0.851 / Virus Database: 579 - Release Date: 28/01/2005


          Comment

          • Norm Mann

            #6
            Re: Reading .txt files


            "slickn_sly " <bng_s@hotmai l-dot-com.no-spam.invalid> wrote in message
            news:41fcc5d0$3 _2@127.0.0.1...
            [color=blue]
            > oops...Any idea on how may i go about taking that input.txt file and
            > using insertion sort to sort it?[/color]

            Most of us have ideas on how to do this because we did something like this
            for our own homework problems. We'll be glad to help you when you post some
            code showing that you've made a reasonable attempt to do it yourself. I
            would suggest that if you're having problems, your best first source would
            be your instructor, next would be your books or the "class guru". Hoping to
            get the answer handed to you (without doing any of the work) from the
            newsgroup is the last thing to try because most people believe you must do
            you own work to learn anything and the response time for getting any answer
            will vary, assuming you get an answer. If you're really having that much
            trouble, maybe you should drop the course and try again later. If the
            course you're taking *is* the programming fundamentals course, then the
            instructor believes that you have all the information neccessary to do the
            task and you definitely should talk to your instructor.

            HTH

            -NM



            Comment

            • Randolf Richardson

              #7
              Re: Reading .txt files

              "bng_s@hotm ail-dot-com.no-spam.invalid (slickn_sly)" wrote in comp.lang.java:
              [color=blue]
              > How do you read a .txt file and have the compiler print out what's in
              > the text file?[/color]

              If you're using an Operating System that has a DOS prompt, you can do
              the following to get your compiler to print (I'll assume your printer is
              connected to LPT1:):

              JavaC filename.txt | sort > lpt1.dos

              Depending on the contents of your text file, the output, which although
              will be sorted alphabetically, will probably be quite different from the
              original contents of the text file.

              You'd probably be better off using the following:

              Type filename.txt | sort > lpt1.dos

              Of course, in both of these examples the Java Compiler isn't actually
              doing the printing -- your Operating System is, but it's more likely that you
              meant that the output should be sent to the printer.

              --
              Randolf Richardson, pro-active spam fighter - rr@8x.ca
              Vancouver, British Columbia, Canada

              Sending eMail to other SMTP servers is a privilege.

              Comment

              Working...