Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read in 2 input .txt files?

 
Madysen Rayne
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic