• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to preserve newline

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}
}
}
 
Sheriff
Posts: 22783
131
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
Please Use Code Tags.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both your versions contain ugly hacks or sloppy mistakes. Here's what you should do:

 
Rob Spoor
Sheriff
Posts: 22783
131
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
Except that OutputStreamReader should be OutputStreamWriter
 
sv.srikrishna kitti
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much guys
 
sv.srikrishna kitti
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Now newline issue is resolved but some arabic characters are appearing as ?.please help me
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic