• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to preserve newline

 
sv.srikrishna kitti
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have file which contains data in EBCIDC format.The data contains both english and arabic characters.I have to convert into UTF-8.Iam able to convert the data successfully into unicode.But iam losing out newline.All the charaters are appearing in the single line after conversion to unicode.Please help me.What is wrong with this code.

import java.io.*;
class FileRead1
{
public static void main(String args[])
{
try{
// Open the file that is the first
// command line parameter

FileInputStream fstream = new FileInputStream("C:\\sabb.txt");

File outfile = new File( "C:\\100.txt" );

FileOutputStream fout = new FileOutputStream( outfile);


// Get the object of DataInputStream

InputStreamReader is = new InputStreamReader( fstream, "cp420");

//DataInputStream in = new DataInputStream(fstream);

BufferedReader reader = new BufferedReader(is);

String strLine;
//Read File Line By Line
while ((strLine = reader.readLine()) != null) {

byte[] output =strLine.getBytes("UTF-8" );
fout.write(output);
fout.close();
}

}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Use Code Tags.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading the documentation might help:

http://java.sun.com/j2se/1.5.0/docs/api/java/io/BufferedReader.html#readLine%28%29
 
sv.srikrishna kitti
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I tried this way also.Still getting the same problem .All the converted text appears in a single line.Please help me.


 
Paul Clapham
Sheriff
Posts: 21002
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both your versions contain ugly hacks or sloppy mistakes. Here's what you should do:

 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except that OutputStreamReader should be OutputStreamWriter
 
sv.srikrishna kitti
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much guys
 
sv.srikrishna kitti
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Now newline issue is resolved but some arabic characters are appearing as ?.please help me
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15219
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sv.srikrishna kitti wrote:Now newline issue is resolved but some arabic characters are appearing as ?.please help me

The reason why that happens probably doesn't have anything to do with your program, but with the software that you use to display the output text. Where and how are you displaying the output? Does the font that is being used contain arabic characters? If not, they might appear as '?'. Does the software that you use to display the output understand UTF-8 encoding?
 
sv.srikrishna kitti
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use microsoft word with the font windows arabic for display purporse.I don't think it is something to do with software because when i was reading byte by byte as mentioned in previous posts all the arabic characters were getting displayed properly but new line was the problem.But now newline issue is resolved but now having problem with some arabic characters.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic