problem with Text files format

Hello,

thanks once more for your help at my previous thread, "Vector Problems...".

Well the assignment has moved on and now it's the time to write some data in files.

I am using the following code:

bw.write("{");

bw.write("\n\tComponents");

bw.write("\t{\n");

for (int i=indexes[0];i<indexes[1];i++)

{

bw.write("\t\tMotherboard"+"\n");

bw.write("price = "+Float.toString(components.elementAt(i).getPrice())+"\n");

}

bw.close();

and the requested output file format should be:

{

Components

{

Motherboard

{

price = 10

...

(Corresponding to the code above, normally there are other fields than "price", but the logic is the same I guess).

Unfortunately, the output text file is something like:

{Components{Motherboard{price = 10

So the "\n" characters are ignored, but the "\t" chars aren't ignored.

Any help would be greatly appreciated.

philimon>

[1306 byte] By [philimonasa] at [2007-11-27 10:44:40]
# 1

You should use bw.newLine() method for new lines as it chooses the correct format depending on platform (DOS, Mac, UNIX).

Some special characters sometimes wont be displayed (or will be displayed as small squares) depending on how you view them (notepad, Word, Open Office etc).

Try this

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.IOException;

public class Tester {

public static void main(String[] args) throws IOException {

BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\temp.txt"));

bw.write("Line\tOne\tSpaced\tBy\ta\tTab");

bw.newLine();

bw.write("Line two");

bw.close();

}

}

_helloWorld_a at 2007-7-28 20:08:14 > top of Java-index,Java Essentials,New To Java...
# 2

Thanks a lot, that worked just fine.

However I don't have time to finish the rest of the assignment..

philimon

philimonasa at 2007-7-28 20:08:14 > top of Java-index,Java Essentials,New To Java...
# 3

> However I don't have time to finish the rest of the

> assignment..

I've been there and it sucks :(

petes1234a at 2007-7-28 20:08:14 > top of Java-index,Java Essentials,New To Java...