1
\$\begingroup\$

I recently posted a question about this, but was not really sure where to go. I've gotten some progress, and have generated some simple noise here:

http://pastie.org/5408655

That works well enough for me, but I would really like to be able to save the points into an ascii text file. currently it's formatted so that something like this:

11111111

11111111

11111111

11111111

would create a square. I need to save in this format with the points(and lines connecting them) generated in the method above.

Essentially, I need to write the array of points created in the first example to a text file formatted like the second example. EDIT: I ended up using serialization. This method makes it un-editable, but works for my purposes, I can really have good terrain generation now. here's my code: http://pastie.org/5455624 Everything is working excellently. Thanks to all those who helped

\$\endgroup\$
  • \$\begingroup\$ Your question, if I'm interpreting it correctly, is: "how do I write a text file from Java?" Is that correct? \$\endgroup\$ – Trevor Powell Nov 21 '12 at 4:20
  • \$\begingroup\$ No, not exactly. I need to write an array of points into a text file in the format used in my example. Edited for clarity. \$\endgroup\$ – Dylan Katz Nov 21 '12 at 4:28
  • \$\begingroup\$ How do your points look like then? I mean, do you have Java classes for them? Maybe a bit code would help. \$\endgroup\$ – Markus Nov 21 '12 at 7:47
  • \$\begingroup\$ What do you mean? I put the code in the post. The class "Point" is built in to java. \$\endgroup\$ – Dylan Katz Nov 21 '12 at 20:50
  • \$\begingroup\$ Paste your solution as an answer and accept it. Maybe someone can make use of it later. \$\endgroup\$ – Anko Dec 9 '12 at 1:06
3
\$\begingroup\$

You could consider Serialization

http://www.tutorialspoint.com/java/java_serialization.htm

Advantages

  1. Hides your values
  2. Easier to save/load

Disadvantages

  1. Values can not be modified in text editor.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.