473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 27621
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Olivier Maurice | last post by:
Hi all, I suppose some of you know the program Redmon (type redmon in google, first result). This neat little tool allows to hook up any functionality to a printer by putting the file printed...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
6
by: Rajorshi Biswas | last post by:
Hi folks, Suppose I have a large (1 GB) text file which I want to read in reverse. The number of characters I want to read at a time is insignificant. I'm confused as to how best to do it. Upon...
2
by: nnimod | last post by:
Hi. I'm having trouble reading some unicode files. Basically, I have to parse certain files. Some of those files are being input in Japanese, Chinese etc. The easiest way, I figured, to distinguish...
7
by: jccorreu | last post by:
I've got to read info from multiple files that will be given to me. I know the format and what the data is. The thing is each time we run the program we may be using a differnt number of files,...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
10
by: Tyler | last post by:
Hello All: After trying to find an open source alternative to Matlab (or IDL), I am currently getting acquainted with Python and, in particular SciPy, NumPy, and Matplotlib. While I await the...
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
4
by: Miner Jeff | last post by:
Hello, I have a basic question about reading files. I have several data files where the filenames are identical except for a short (3 character) prefix. I inherited this code and the person who...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.