The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


reading and printing more than 1 files.

Posted by Pearl Lee on January 18, 2001 at 9:51 PM

I made 3 text files, and now I want to read them and print the contents of the texts files. I don't know how to do that. First, I tried to put 3 filenames in a String array, and use the loop to print them out, but only one file (the last file was read and printed out). Here are my codes:

private static Comparable[] readFromFile()throws IOException
String[] fileName = {"firstInt.txt", "ascenInt.txt", "descenInt.txt", "firstDouble.txt", "ascenDouble.txt", "descenDouble.txt"};
Comparable [] numbers = new Comparable[size];
int[] readNumbers = new int [size];
for(int i = 0; i < fileName.length; i++)
FileReader fr = new FileReader(fileName[i]);
BufferedReader inFile = new BufferedReader(fr);
for(int j=0; j < size; j++)
numbers[j] = (Comparable)(inFile.readLine());

return numbers;
I have another print method which invoke this from file method, and it is called in main (print(readFromFile());)

Is there anything wrong with my codes? Any helps are very, very appreciated. Thanks. Pearl


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us