Java question.
#1
DVD Talk Limited Edition
Thread Starter
Java question.
All righty, I'm finally caving in and trying to learn Java. How does one read from a file? I assume it uses FileInputStream, but am having trouble finding online examples for it. If I wanted to read from a txt file containing numbers on each line, and put those numbers into an array, how would I read from the file? I know this is easy, but I'm just starting
.

#2
DVD Talk Hero
#3
Banned
Join Date: Aug 2001
Posts: 482
Likes: 0
Received 0 Likes
on
0 Posts
If the documenation confuses you, you can post to the Java forum at www.gamedev.net. It should get answered within 24 hours of posting.
BTW, this should have gone into the computer forum. If you need any more help I can help ya with most java stuff.
BTW, this should have gone into the computer forum. If you need any more help I can help ya with most java stuff.
#4
Senior Member
Join Date: Oct 2000
Location: Addison, TX
Posts: 905
Likes: 0
Received 0 Likes
on
0 Posts
This is probably the easiest way
import java.io.*
import java.util.*
public class NumberRead
{
public static void main(String[] args)
P
if (args.length > 0)
{
try
{
int number = '';
Vector numbers = new Vector();
FileReader fileReader = new FileReader(new File(args[0]);
while (number = fileReader.read() != -1)
{
numbers.add(new Integer(number));
}
// do whatever you want with numbers
}
catch (Exception e)
{
System.out.println("Exception = " + e.toString());
}
}
}
}
import java.io.*
import java.util.*
public class NumberRead
{
public static void main(String[] args)
P
if (args.length > 0)
{
try
{
int number = '';
Vector numbers = new Vector();
FileReader fileReader = new FileReader(new File(args[0]);
while (number = fileReader.read() != -1)
{
numbers.add(new Integer(number));
}
// do whatever you want with numbers
}
catch (Exception e)
{
System.out.println("Exception = " + e.toString());
}
}
}
}
Last edited by Shay; 09-17-01 at 12:36 AM.