469,328 Members | 1,315 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

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
*---------------------------------*
Jul 17 '05 #1
6 27330
slickn_sly wrote:
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
*---------------------------------*


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

The compiler does not print out the file, your program does.
Jul 17 '05 #2
On Sun, 30 Jan 2005 11:28:40 +0100, anonymous wrote:
The compiler does not print out the file, your program does.


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
Jul 17 '05 #3
> anonymouswrote:
slickn_sly wrote:
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
*---------------------------------*

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

The compiler does not print out the file, your program
does.[/quote:af0243bd45]
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
*---------------------------------*
Jul 17 '05 #4
How do you read a .txt file and have the compiler print out what's in
the text file?


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("MyFile.txt");
BufferedReader br = new BufferedReader(fr);
String line = br.readLine();
While (line !=null)
{
System.out.println(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
Jul 17 '05 #5

"slickn_sly" <bn***@hotmail-dot-com.no-spam.invalid> wrote in message
news:41**********@127.0.0.1...
oops...Any idea on how may i go about taking that input.txt file and
using insertion sort to sort it?


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

Jul 17 '05 #6
"bn***@hotmail-dot-com.no-spam.invalid (slickn_sly)" wrote in comp.lang.java:
How do you read a .txt file and have the compiler print out what's in
the text file?


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.
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Olivier Maurice | last post: by
19 posts views Thread by Lionel B | last post: by
6 posts views Thread by Rajorshi Biswas | last post: by
2 posts views Thread by nnimod | last post: by
6 posts views Thread by arne.muller | last post: by
10 posts views Thread by Tyler | last post: by
4 posts views Thread by Miner Jeff | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.