aspose file tools*
The moose likes Beginning Java and the fly likes Putting numbers into array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Putting numbers into array" Watch "Putting numbers into array" New topic
Author

Putting numbers into array

MR Chahal
Greenhorn

Joined: Nov 27, 2005
Posts: 14
Hello

I have a file with 6 numbers like this

1 <- first line
2
3
4
5
6 <- last line

The file is opened into a jTextArea in the above manner. But how can i insert those numbers into an int array?
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
well i think all you have to do is put the file in the same folder..

and do this in the main program



then do the :



something along those lines I believe...

someone plz correct me if i'm wrong...

-Justin-


You down with OOP? Yeah you know me!
MR Chahal
Greenhorn

Joined: Nov 27, 2005
Posts: 14
Hello Justin

I get this error:

symbol : class Scanner
location: class fio.Tframe
Scanner scan = new Scanner(f);

I know i have to import something but not sure what. How do i solve this?
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Mr. MR,

Could you pls post the whole code so that we can analyze...???
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38353
    
  23
If you need an import, it would be import java.util.Scanner;

CR
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Be aware that java.util.Scanner is only since 1.5. If you are using this version of Java, or later, consider nextInt rather that just readLine, as well. If you are using an earlier version of Java, check out java.io.BufferedReader. And it's never a bad idea to study the IO tutorial:

http://java.sun.com/docs/books/tutorial/essential/io/index.html


There is no emoticon for what I am feeling!
MR Chahal
Greenhorn

Joined: Nov 27, 2005
Posts: 14
I have 1.4.2 hency why the scanner wont work. I can load and save text files with no problem. What i am doing now is take the text in the jTextArea and puting it in a String. But i dont know how to put those 6 numbers from the string into an array. Any help will be appreciated.
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
umm...

i think versions before 1.5 have scanner. but to create the object

requires different syntax... like

Scanner scan = Scanner.create(file);

and in the while loop i made a boo boo, don't let info += scan.nextLine,

only info = scan.nextLine();

and you could declare info to be an int, and say.

info = scan.nextInt();

wasn't thinking i guess.

and you have to import the scanner package.

so before the...



type...



I lied!! the Scanner scan = Scanner.create(); only applies to the first

beta of java 1.5... sorry!

-Justin-
[ May 03, 2006: Message edited by: Justin Fox ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Putting numbers into array