Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

simple help

1 view
Skip to first unread message

xinxin

unread,
Apr 19, 2008, 9:44:24 AM4/19/08
to
String format="\n"+year+"年"+month+"月\n"+day+"日"+hour+"时"+min+"分" + "
"+task;

FileWriter writer = new FileWriter(taskFile, true);

writer.write(format);
writer.write(format);//I expect this words appear in newline in my
file but I am frustrated who can
// tell me why .thanks in advance.


xinxin

unread,
Apr 19, 2008, 9:55:27 AM4/19/08
to
On 4月19日, 下午9时44分, xinxin <jnzhouxin...@gmail.com> wrote:
> String format="\n"+year+"年"+month+"月\n"+day+"日"+hour+"时"+min+"分" + "
> "+task;
>
> FileWriter writer = new FileWriter(taskFile, true);
>
> writer.write(format);
> writer.write(format);//I expect this words appear in newline in my
> //file but I am frustrated .who can tell me why .thanks in advance.


>

Alex.From...@gmail.com

unread,
Apr 19, 2008, 10:03:48 AM4/19/08
to

They should be new lines.
Since you use Writer they are localized to your local system.
It's possible that you read in tool which is set for another
localization. Simplest example would be if you write file for UNIX
system and try to read it in Windows. Or Mac vs UNIX or whatever.
Look inside your file character by character and you should understand
what's going on.

Alex.
http://www.myjavaserver.com/~alexfromohio/

Jeff Higgins

unread,
Apr 19, 2008, 10:16:40 AM4/19/08
to

xinxin wrote:
On 4月19日, 下午9时44分, xinxin <jnzhouxin...@gmail.com> wrote:
> String format="\n"+year+"年"+month+"月\n"+day+"日"+hour+"时"+min+"分" +
> "
> "+task;
>
PrintWriter writer =
new PrintWriter(new BufferedWriter(new FileWriter(taskFile, true)));

writer.println(format);

Mark Space

unread,
Apr 19, 2008, 4:47:07 PM4/19/08
to

Well, you haven't show us any newlines here. Does "task" have one? If
not then you have to add one.

Jeff had the best answer, use println from the PrintWriter class.

If you cannot for some reason, then you'll have to add the newlines
manually. Use System.getProperty("line.separator") to get the correct
newline for your system in that case.

Roedy Green

unread,
Apr 19, 2008, 6:53:03 PM4/19/08
to
On Sat, 19 Apr 2008 06:44:24 -0700 (PDT), xinxin
<jnzhou...@gmail.com> wrote, quoted or indirectly quoted someone
who said :

> FileWriter writer = new FileWriter(taskFile, true);
>
> writer.write(format);
> writer.write(format);//I expect this words appear in newline in my
>file but I am frustrated who can
> // tell me why .thanks in advance.

see http://mindprod.com/applet/fileio.html
to generate you some code. You will need a PrintWriter.println() to
get the newlines right for your platform.

--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

xinxin

unread,
Apr 20, 2008, 12:55:39 AM4/20/08
to
On 4月20日, 上午6时53分, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:

> On Sat, 19 Apr 2008 06:44:24 -0700 (PDT),xinxin
> <jnzhouxin...@gmail.com> wrote, quoted or indirectly quoted someone

> who said :
>
> > FileWriter writer = new FileWriter(taskFile, true);
>
> > writer.write(format);
> > writer.write(format);//I expect this words appear in newline in my
> >file but I am frustrated who can
> > // tell me why .thanks in advance.
>
> seehttp://mindprod.com/applet/fileio.html

> to generate you some code. You will need a PrintWriter.println() to
> get the newlines right for your platform.
>
> --
>
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com
you are so great. I fell so great . i use
System.setProperty("line.separator","\r\n");and it works .thank you
very mush.


Roedy Green

unread,
Apr 28, 2008, 12:58:12 AM4/28/08
to
On Sat, 19 Apr 2008 21:55:39 -0700 (PDT), xinxin
<jnzhou...@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>you are so great. I fell so great . i use


>System.setProperty("line.separator","\r\n");and it works .thank you
>very mush.

You don't need to do that. The line.separator property is already set
for you to the platform default.

0 new messages