i need to write a txt file containing some tabs

i'm trying to write a text file containing tabs and more than one line.

as this file should be in a definite specific format:

5

346

346

346

346

...etc.

i am using that code:

try{

FileOutputStream fos =new FileOutputStream("rofy.txt");

OutputStreamWriter osw =new OutputStreamWriter(fos);

String i ="5\n4\t3\t6";

char[] output = i.toCharArray();

osw.write(output);

osw.close();

}

catch (IOException e)

{

e.printStackTrace();

}

but it seems that the \t and \n can\t be read correctlt in the file , as i don't get what i am expecting ..

can any one tell me please how can i reach what i need to do ?

thanks in advance.

regards,

D.Roth.

[1119 byte] By [d_rotha] at [2007-11-26 20:30:49]
# 1
Try without the charArray, just the String. It should work okay.
kikemellya at 2007-7-10 1:20:23 > top of Java-index,Java Essentials,New To Java...
# 2
yes thank u . the tab worked , but the new line still doesn't work . so?
d_rotha at 2007-7-10 1:20:23 > top of Java-index,Java Essentials,New To Java...
# 3
What you need to do is post a tiny complete example program demonstrating your problem,because I think your error is in your logic.
DrLaszloJamfa at 2007-7-10 1:20:23 > top of Java-index,Java Essentials,New To Java...
# 4

Demo:

import java.io.*;

public class IOTest {

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

String filename = "test.txt";

String test = "5\n4\t3\t6";

PrintWriter out = new PrintWriter(filename);

out.print(test);

out.close();

FileReader in = new FileReader(filename);

int ch;

StringBuilder input = new StringBuilder();

while ((ch = in.read()) != -1) {

input.append((char)ch);

}

in.close();

System.out.format("test equals input = %b%n", test.contentEquals(input));

}

}

DrLaszloJamfa at 2007-7-10 1:20:23 > top of Java-index,Java Essentials,New To Java...
# 5

> What you need to do is post a tiny complete

> example program demonstrating your problem,

> because I think your error is in your logic.

ok , now after trying solution in reply # 2 , i have my file :

5436 ..etc.

i mean i can have the tab out there in the file, but i don't get the new line thing to show up there .

i have some missing info. about how to get a new line in my text file.

can u get me now?

d_rotha at 2007-7-10 1:20:23 > top of Java-index,Java Essentials,New To Java...
# 6
What does "show up" mean? If it means you don't see separate lines when you load the file into Notepad, that's Notepad's fault. Try any other text editor ever written for Windows and your problem should go away.
DrClapa at 2007-7-10 1:20:23 > top of Java-index,Java Essentials,New To Java...
# 7
My code in reply #4 writes out the new line character.Again, I'd bet the error is in your logic, but since you haven't posted a small complete example program, we'll never know for sure.
DrLaszloJamfa at 2007-7-10 1:20:23 > top of Java-index,Java Essentials,New To Java...
# 8

> What does "show up" mean? If it means you don't see

> separate lines when you load the file into Notepad,

> that's Notepad's fault. Try any other text editor

> ever written for Windows and your problem should go

> away.

Yes, depending on your text editor and the formatting it provides the results can be different. If you opened the file in Word or Open Office it would respect the formatting.

kikemellya at 2007-7-10 1:20:23 > top of Java-index,Java Essentials,New To Java...
# 9

ok , thank u everybody , i got it , it's cuz of the editor as u said.

i tried solution # 4, it worked , as well as #2 . thank u again .

as for my small program explaining my question ( i sent a sample code decribing what i'm doing in #1)

thanks.

regards..

D.Roth.

d_rotha at 2007-7-10 1:20:23 > top of Java-index,Java Essentials,New To Java...
# 10

you can use split method of type string.

try{

FileReader fr = new FileReader("test.txt");

BufferedReader br = new BufferedReader(fr);

String s = br.readLine();

while(s!=null)

{

String[] str = s.split(" + ");

}

}

catch(Exception e)

{

e.printStackTrace():

}

make sure to import BufferedReader

fastmikea at 2007-7-10 1:20:23 > top of Java-index,Java Essentials,New To Java...
# 11
disregard my previous post. i thought you had problems in reading file not the output.
fastmikea at 2007-7-10 1:20:23 > top of Java-index,Java Essentials,New To Java...