Go Back  DVD Talk Forum > General Discussions > Tech Talk
Reload this Page >

Java question.

Tech Talk Discuss PC Hardware, Software, Internet and Other Technology

Java question.

Old 09-16-01, 11:16 PM
  #1  
DVD Talk Limited Edition
Thread Starter
 
cartman's Avatar
 
Join Date: Oct 1999
Location: SP, Colorado
Posts: 5,344
Likes: 0
Received 1 Like on 1 Post
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 .
Old 09-16-01, 11:17 PM
  #2  
DVD Talk Hero
 
Join Date: Nov 1999
Posts: 36,983
Likes: 0
Received 1 Like on 1 Post
http://java.sun.com/products/jdk/1.2...api/index.html


everything you ever wanted to know
Old 09-16-01, 11:21 PM
  #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.
Old 09-17-01, 12:33 AM
  #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());
}
}
}
}

Last edited by Shay; 09-17-01 at 12:36 AM.
Old 09-17-01, 12:37 AM
  #5  
Senior Member
 
Join Date: Oct 2000
Location: Addison, TX
Posts: 905
Likes: 0
Received 0 Likes on 0 Posts
That code is just off the top of my head. So there are probably some typo's in it. But it should get you started. Let me know if you have any other questions.

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Thread Tools
Search this Thread

Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service - Do Not Sell My Personal Information -

Copyright 2021 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.