The Artima Developer Community
Sponsored Link

Java Answers Forum
FileWriter cant recognise '\n' character

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Tanvir Hossain

Posts: 53
Nickname: tanvirtonu
Registered: Feb, 2006

FileWriter cant recognise '\n' character Posted: Nov 27, 2007 6:56 AM
Reply to this message Reply
Advertisement
I wrote a simple program which will write a file as I want the content to be.But I cant write the file string line by line.The produced file shows the content in a single line and cant recognize the line feed character '\n'. How to write a file this way.My code for writing the file is-
String fileContent="This is 1st line\nThis is 2nd line";
public void SaveAs()
	{
 
		JFileChooser jfc = new JFileChooser();
		int r = jfc.showSaveDialog(this);
 
		if (r== JFileChooser.APPROVE_OPTION)
		{
			FileName = jfc.getSelectedFile().getPath();
			FileName=FileName+".txt";
			writeFile(FileName);
			
		}
 
	}//End of SaveAs() Method
 
  
  
  public void writeFile(String fn)
	{
		try{
 
			FileWriter fw = new FileWriter(fn);
 
			fw.write(fileContent);
 
			fw.close();
 
 
		}catch(FileNotFoundException fnfe){}
		 catch(IOException ioe){}
 
	}//End of writeFile(String fn) Method
  

And how can I write any ANY character in keyboard in textfile.PLS HELP ME

Topic: FileWriter cant recognise '\n' character Previous Topic   Next Topic Topic: Constants

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use