Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Writing ArrayList to text file

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 98
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the full class? Can't tell much from the snippet.


S
 
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

the below code is working for me.

try {
DataOutputStream dos= new DataOutputStream(new BufferedOutputStream(new FileOutputStream("/tmp/visitcount/countt")));
//System.out.println("before"+countnum);
ArrayList<Integer> ar= new ArrayList<Integer>();
ar.add(77);
ar.add(88);
ar.add(99);
for(int i=0;i<ar.size();i++){
System.out.println("before"+ar.get(i));
dos.writeInt(ar.get(i));
System.out.println("After"+ar.get(i));
}
dos.close();
} catch (IOException e) {
e.printStackTrace();
}


can you try this code....in your code why for loop dosen't contains { and } and use outStream.close(); after loop is completed.
 
Dan Todd
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've cut out the irrelevant parts of the code (other cases). Still pretty long though.

 
Stuie Clarky
Ranch Hand
Posts: 98
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic