This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Save a String to a Text File,

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am Trying to Save a String to a Text File..


 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the question is...?
 
david foley
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i get my toString into a Text file,

 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the code you provided cannot be compiled as is. First of all, FileWriter class has no write() method, so out.write(); will prevent you from compiling the code. Also I think there is one closing brace more than it should be, but I will suppose you made a mistake when pasting the code.

There is also something that looks wrong with the logic. You are trying to write to file inside the for loop. So what the output file would contain is the amount returned only from the last element of your StaffList array increased by value of basic. However, if you wanted to save the data for each element of your StuffList array, you would have to initialize FileWriter before you enter the for loop, write the data inside the for loop, and close the output after it. Basically, it should look like this:

And what's the purpose of the code marked as Reading a file? If you need to read the file too, than you should put that in separate method. Also, naming a method holidays() for this task doesn't seem like a very good choice to me.
 
david foley
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I Fixed up the Loop,

but my main problem doesnt seem to want to fix itself,

Here is my String



I Used a ArrayList and got the String to Print to text file, but i cant seem to get it to work on an Array
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try this?
 
You don't like waffles? Well, do you like this tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!