aspose file tools*
The moose likes Beginning Java and the fly likes Reading file Input and Output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading file Input and Output" Watch "Reading file Input and Output" New topic
Author

Reading file Input and Output

Mel Ram
Greenhorn

Joined: Sep 30, 2009
Posts: 12
You guys have been great at helping figure things out so I'm appreciating your responses!!

My next problem is this, I am suppose to have a program that opens a file and read it as and prints it out. I've done that and that is great. But I then need to open a new file and have that print out as well. I've been going in circles with that. I've already created the new file. here's the code that I have now.



Here's what I thought I could do:



So what the second part of the program is suppose to do is read another file that contains the same names that were in the first file, but in alphabetical order. I'm suppose to show both. I already created that file, like I said, in alpha order, so it's all ready to go. sigh. Any takers?
Andrew Tangen
Greenhorn

Joined: Dec 07, 2009
Posts: 1
I can't help you without knowing what the problem is. Your second grouping of code will work fine to read the first/last names after only looking at it for 5 seconds, because its no different from your first batch there. You didn't even need that second class as you said you already had the second file in alpha order.

What was the expected behavior opposed to what actually happened?
Mel Ram
Greenhorn

Joined: Sep 30, 2009
Posts: 12
Andrew Tangen wrote:I can't help you without knowing what the problem is. Your second grouping of code will work fine to read the first/last names after only looking at it for 5 seconds, because its no different from your first batch there. You didn't even need that second class as you said you already had the second file in alpha order.

What was the expected behavior opposed to what actually happened?


Ok.. here's what the problem states. FYI, this problem is not taken from any textbook. This is a problem from the teacher himself.

Write a program that reads a file of names where each name is a string consisting of a person’s first name, followed by a blank, then followed by the person’s last name. (Assume that the file contains at most twenty names.) Create a new file with the same names, but where each name is in the form: last name, followed by a comma, followed by a space, then followed by the person’s first name. Assume that the original file is in no particular order, and write the new file in alphabetical order based on last name.


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36575
    
  16
I think this is a case for some slightly more old-fashioned technology. Write a file of names, on paper, like this
Mel Ram
Andrew Tangen
Campbell Ritchie
Write down some way of putting them into some sort of collection. Write down a way of sorting them, then write how you think you can put them into a new file. And remember you want this in Object-Oriented format. So you need a class to record the names in.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading file Input and Output
 
Similar Threads
Determining the location of the file
Creating array of objects from user input and saving to a file
Read in file
[Resolved]java.util.NoSuchElementException problem after displaying the information from text file
Scan a text file.