My problem is:

  • I've try many times with DataOutputStream, FileWriter but I cannot write intergers into a file as I wanted.
  • I seemed to succeed but after writing them into a file, when I open it with notepad, I can read it. They all tuned out to many strange shape (such as ! # and square).

So is there any one can help me deal with my problem. For instance I want to write in such this format:

Output.dat
1 2 3
3
4
5
6

thkyvrmuch.

Try to read this tutorials http://java.sun.com/docs/books/tutorial/essential/io/. The task is not difficult and you should understand it, however if you will have any problems, just update your question and provide any code examples you working on

Good luck

Use a BufferedWriter instead of DataOutputStream. You created a BufferedWriter like so:

BufferedWriter writer = new BufferedWriter( new FileWriter("myFile.txt") );

The tutorial that peter_budo linked should provide any other info you need on usage.

Thank you all very much indeed.

I've try PrintStream and superisingly, it's very easy.
I can use print() and println() as usual as printing to console.

I've made a worth experience and I hope my thread will be useful for some one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.