• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Creating a text file using FileWriter

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a text file using FileWriter.
I can see it properly when i open it with MS-Word,but when i try to open it with notepad or wordpad.
It is not displayed properly.
To print this file, which docflavor should i use?
Whether it is docflavor.INPUT_STREAM.TEXT_PLAIN or wat???
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sudheer raj:
I have created a text file using FileWriter.
I can see it properly when i open it with MS-Word,but when i try to open it with notepad or wordpad.
It is not displayed properly.



Strange, if this is a text file it should ideally open properly in notepad and not in MS-Word(as it is not a ms word style document.)
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's impossible to understand what exactly you mean by "not displayed properly."

To get better help sooner, post a SSCCE that clearly demonstrates the problem.
 
Sheriff
Posts: 22649
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nitesh Kant:


Strange, if this is a text file it should ideally open properly in notepad and not in MS-Word(as it is not a ms word style document.)


Actually, MS Word can also handle plain text files. So the problem is in how the file is written.

Sudheer, can you show us how you create the FileWriter and what you write to it?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rob Prime:

Actually, MS Word can also handle plain text files.


I see.
 
sudheer raj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
str="xyz\nabcd\n";
char buff[]=new char[str.length()];
str.getChars(0,str.length(),buff,0);
try{
File f1=new File("/logs","temp.txt");

FileWriter fo=new FileWriter(f1);


fo.write(buff);
fo.close();
}catch(IOException ioe){

}

This way i created the file.
 
Rob Spoor
Sheriff
Posts: 22649
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strange, that code works here just fine.
Well, with the exception that Notepad doesn't recognize the line break, but that is because Windows requires \r\n, not just \n. In fact, use System.getProperty("line.separator") instead; that way it'll work with all operating systems.
 
sudheer raj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so instead of \n if i use \r\n then will it open properly in the notepad?
one more thing now i want to print this file
while specifying the docflavor which one should i use
whether it is docflavor.INPUT_STREAM.TEXT_PLAIN or wat??
 
sudheer raj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you RobPrime.
Now its getting displayed properly
And even its getting printed from the program

Thanks a lot
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic