File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How to read in 2 input .txt files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to read in 2 input .txt files?" Watch "How to read in 2 input .txt files?" New topic

How to read in 2 input .txt files?

Madysen Rayne

Joined: Feb 03, 2004
Posts: 11
Hello all
I have my program written and works well. I can get it to execute fine when i have this in my code:

What i want to do though in the DOS window is to be able to type
" java MergedSortedLists minors.txt majors.txt " so that i can test my code on any files without having to go into the code and manually change it each time. and this is what i come up with so far:
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
one quick note below,

public class MergedSortedLists
public static void main(String [] args) throws IOException
List theList = new LinkedList();
String fileName = args[0];
String fileName2 = args[0]; // you mean args[1] here ?
File inFile = new File(fileName );
File inFile2 = new File(fileName2 );
BufferedReader fileInput = new BufferedReader( new FileReader(inFile));
BufferedReader fileInput2 = new BufferedReader( new FileReader(inFile2));

String oneLine = fileInput.readLine();//reads in first line of 1st record
PersonRecord theRecord = new PersonRecord(oneLine);
Madysen Rayne

Joined: Feb 03, 2004
Posts: 11
rawr! it worked
I didn't realize that I needed a 1 in there, which now makes sense... no wonder it was just reading in the same file twice...!
I agree. Here's the link:
subject: How to read in 2 input .txt files?
It's not a secret anymore!