Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

filling array from a text file

807601Jan 25 2008 — edited Jan 25 2008
can anyone tell me the right approach for filling an array from a text file?

Here is the code I am working with. This code is successfully displaying the contents of the file to screen.
I am trying to get the contents of the file and fill the int aTerm array
 
import java.io.*;


public class CheckFile
{
	public static void main(String[] args) throws IOException
	{
		String sFileName = "Week4_Data.txt";
		File years = new File(sFileName);
		InputStream iStream;
		OutputStream oStream;
		int c;
		iStream = new FileInputStream(years);
		oStream = System.out;
		int aTerm [] = {0,0,0};
		try
		{
			while((c=iStream.read()) != -1)
			oStream.write(c);

		}

		catch(IOException e)
		{
			System.out.println("Error: " + e.getMessage());
		}

		finally
		{
			iStream.close();
			oStream.close();
		}


	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 22 2008
Added on Jan 25 2008
23 comments
200 views