wood burning stoves*
The moose likes Beginning Java and the fly likes How to add elements from a file into an Array List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to add elements from a file into an Array List" Watch "How to add elements from a file into an Array List" New topic
Author

How to add elements from a file into an Array List

Karthik surya
Greenhorn

Joined: Jan 28, 2011
Posts: 2
Hello Everyone

I wanted to read a file and then add the contents of the file into an ArrayList.



and then I also had a catch following try. But when I say cr.add() it is not adding . I have also tried to add using:



Can someone give me any idea of doing it.

Thank you.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14111
    
  16

Welcome to the Ranch.

When you post code, don't double-click the code button. Make sure your source code is in between a [code] start tag and [/code] end tag. I've fixed your post for you.

About your problem: How do you know "it is not adding"? Does your code compile? Does it run? Do you get any error messages? Does the program do something else than you expected? If so, then what did you expect exactly, and how does the actual output differ from that?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Divya Kotamraju
Greenhorn

Joined: Oct 07, 2010
Posts: 21
Hello Even I have the same problem .. IT is giving me a Number format exception. Can someone please help.

Thanks!!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14111
    
  16

Note that you are using token multiple times in line 22. Are you sure that is correct? It's the same string that you are passing to the constructor multiple times. I think you meant to read multiple different tokens from the scanner and pass those for the individual parameters for the constructor.

By the way, why is it that Karthik surya posted the original question, and Divya Kotamraju answers? Are you one person with two accounts? (Oh, now you've edited your answer as if you're someone else???)
Divya Kotamraju
Greenhorn

Joined: Oct 07, 2010
Posts: 21
Hello Jasper,

No I am not the same person as Karthik. Even I am doing similar kind of assignment. So I have posted as a reply to this particular post.
Karthik surya
Greenhorn

Joined: Jan 28, 2011
Posts: 2
Jasper,

No. and regarding this question it is giving me number format exception. I think token contains the next value of the scanned i/p. So I have used it.

Thanks!!
Ed Connery
Ranch Hand

Joined: Mar 11, 2010
Posts: 70
Karthik surya wrote:No. and regarding this question it is giving me number format exception. I think token contains the next value of the scanned i/p. So I have used it.
Take a look at Jesper's first post again. He asked you about seven questions, but you only answered one. The others will give you some key clues to solving the problems with your code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add elements from a file into an Array List