File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Writing ArrayList to text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Writing ArrayList to text file" Watch "Writing ArrayList to text file" New topic

Writing ArrayList to text file

Dan Todd

Joined: May 21, 2013
Posts: 2
I'm trying to write an ArrayList to a text file.

data is the name of the ArrayList.

Both the data.size() and the data.get() methods are returning 'method not found' errors, even though as ArrayList methods they should be working anyways. What's going on?
Stuie Clarky
Ranch Hand

Joined: Nov 09, 2012
Posts: 96

Can you post the full class? Can't tell much from the snippet.


Supun Lakshan Dissanayake
Ranch Hand

Joined: Oct 26, 2012
Posts: 135

Welcome to Java Ranch!!

Did you create a class called ArrayList in your working folder?
So your program will use it instead for java.util.ArrayList class.

Are you better than me? Then please show me my mistakes..
asr chowdary
Ranch Hand

Joined: Mar 14, 2013
Posts: 35

the below code is working for me.

try {
DataOutputStream dos= new DataOutputStream(new BufferedOutputStream(new FileOutputStream("/tmp/visitcount/countt")));
ArrayList<Integer> ar= new ArrayList<Integer>();
for(int i=0;i<ar.size();i++){
} catch (IOException e) {

can you try this your code why for loop dosen't contains { and } and use outStream.close(); after loop is completed.
Dan Todd

Joined: May 21, 2013
Posts: 2
I've cut out the irrelevant parts of the code (other cases). Still pretty long though.

Stuie Clarky
Ranch Hand

Joined: Nov 09, 2012
Posts: 96

In your dispatch method you are passing in a Namelist object called data. How is this Namelist created? Look at how you have implemented this class, make sure it is all working correctly as you are manipulating this in the method, not an ArrayList as you originally stated
I agree. Here's the link:
subject: Writing ArrayList to text file
jQuery in Action, 3rd edition