• Post Reply Bookmark Topic Watch Topic
  • New Topic

notepad not supporting new line character  RSS feed

 
Sujit s dhaygude
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to add notepad recognisabale newline character.
i m using bufferWritter

BufferedWriter out = new BufferedWriter(new FileWriter(new File(fileName)));
out.write(value);
out.close();
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since Notepad is a Windows app, I assume you want to add a return character.
If you're running this code on Windows "out.newLine()" would do the trick; if you run it on some other platform, out.write("\r") is what you want.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect you meant "out.println()", and "\r\n", respectively, for "newLine()" and "\r".
 
amar verma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried using '\r' and '\r\n' both, but it didnt work for me,
Below is the code, here i have a array of bytes
writing it to randomaccess file, before i write a byte array i append '\n' in the array
output file if i open in editplus editor, data looks okie, but notepad doesnt recogrnise it, it prints a garbage char instead of going to next line, any help please

resultBytes = (byte[]) outObj;
resultBytes[resultBytes.length - 1] = '\n'; // Go to next
randInFile.write(resultBytes); // Write each record in file
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here you're showing only "\n", not the two characters "\r\n". Are you sure you tried what we told you to try?
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"\r\n" SHOULD work, if you remember that it is two characters, not just one:


Java was designed to be platform independent and has functionality to make this sort of thing easy. For example, don't hard code the value "\r\n". Use System.getProperties() to obtain the line separator for the platform you are working on. BufferedWriter and PrintWriter, which is what you should use if you are working with character data and don't need random access, have methods which handle line separators as well. Use these features instead of hard-coding values and your code will be more robust AND more portable.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect you meant "out.println()", and "\r\n", respectively, for "newLine()" and "\r".


BufferedWriter doesn't have println(), only newLine().

Of course, CR and LF. Must have been thinking about Mac OS 9 when I wrote that.
 
amar verma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeh, '\r\n' works , sorry i didnt try it correctly last time

here is the code

resultBytes = (byte[]) outObj;
resultBytes[resultBytes.length - 2] = '\r'; // Go to next line
resultBytes[resultBytes.length-1] = '\n'; // Go to next line
randInFile.write(resultBytes); // Write each record in file

It works fine
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!