Results 1 to 4 of 4
Thread: Writing into a text file
- 03-31-2011, 10:27 PM #1
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Writing into a text file
Please help, I am trying to write the contents of an arraylist to a text file but for some reason nothing happens. When I open the text file it is completely empty. Can someone please help me find out why this is. Many thanks in advance.
Java Code:public void writeToFile(){ for (String s : linksArray){ try{ fileOut = new FileOutputStream ("newsDayLinks.txt"); new PrintStream(fileOut).println (s); }catch(IOException e){ System.err.println ("Unable to write to file"); System.exit(-1); } }//for-each ends try { fileOut.close(); } catch (IOException e) { e.printStackTrace(); } }//writeToFile method ends
- 03-31-2011, 10:32 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Try initializing the writers before the loop, then in the loop just directly call println(s).
Also, Are you using this method correctly?
- 03-31-2011, 10:33 PM #3
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Sorry about that, it is actually working. There was a problem with my directory structure
- 03-31-2011, 10:44 PM #4
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
Similar Threads
-
Im writing to a file and i want to skip lines while writing to a text file.
By Broden_McDonald in forum New To JavaReplies: 1Last Post: 02-27-2010, 01:29 AM -
writing to text file problem
By blumdiggity in forum NetworkingReplies: 1Last Post: 02-26-2010, 02:43 PM -
writing to specific line in text file
By mickmos in forum New To JavaReplies: 2Last Post: 04-18-2009, 01:01 PM -
Writing To A Specific Text File Line
By mokonji in forum New To JavaReplies: 1Last Post: 03-02-2009, 08:13 PM -
writing text to file
By notwist in forum New To JavaReplies: 3Last Post: 04-25-2008, 04:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks