Need help to read and write using UTF-16LE

Hello,

I am in need of yr help.

In my application i am using UTF-16LE to export and import the data when i am doing immediate.

And sometimes i need to do the import in an scheduled formate..i.e the export and imort will happend in the specified time.

But in my application when i am doing scheduled import, they used the URL class to build the URL for that file and copy the data to one temp file to do the event later.

The importing file is in UTF-16LE formate and i need to write the code for that encoding formate.

The problem is when i am doing scheduled import i need to copy the data of the file into one temp place and they doing the import.

When copying the data from one file to the temp i cant use the UTF-16LE encoding into the URL .And if i get the path from the URl and creating the reader and writer its giving the FileNotFound exception.

Here is the excisting code,

protected void copyFile(String rootURL, String fileName) {

URL url = null;

try {

url = new URL(rootURL);

} catch(java.net.MalformedURLException ex) {

}

if(url != null) {

BufferedWriter out = null;

BufferedReader in = null;

try {

out = new BufferedWriter(new FileWriter(fileName));

in = new BufferedReader(new InputStreamReader(url.openStream()));

String line;

do {

line = in.readLine();

if(line != null) {

out.write(line, 0, line.length());

out.newLine();

}

} while(line != null);

in.close();

out.close();

} catch(Exception ex) {

}

}

}

Here String rootURL is the real file name from where i have to get the data and its UTF-16LE formate.And String fileName is the tem filename and it logical one.

I think i tried to describe the problem.

Plz anyone help me.

Thanks in advance.

[1892 byte] By [pon_aruna] at [2007-11-27 5:53:31]
# 1
Your catch blocks are empty, so all errors go unnoticed. You're using Writers, which use the platform default encoding (usually not UTF-16LE), don't use Writers, use Streams and OutputStreamWriter/InputStreamReader to specify the encoding.
-Kayaman-a at 2007-7-12 15:46:45 > top of Java-index,Java Essentials,Java Programming...
# 2

Hello,

thanks for yr reply...

I did the as per yr words using StreamWriter but the problem is i need a temp file name to create writer to write into that.

but its an logical one and its not in real so if i create Streamwriten in that its through FileNotFound exception.

The only problem is the existing code build using URL and i can change all the lines and its very difficult because its vast amount of data.

Is anyother way to solve this issue?

Once again thanks..

pon_aruna at 2007-7-12 15:46:45 > top of Java-index,Java Essentials,Java Programming...
# 3
Hello,Anyone plz help meHow can i assign UTF16-LE in URL class....Thanks in Advance
pon_aruna at 2007-7-12 15:46:45 > top of Java-index,Java Essentials,Java Programming...
# 4

Jeez...

I told you, use StreamWriter/Readers and specify the encoding. I couldn't understand what you were talking about files there, but that doesn't matter

In this way, and same for OutputStreamWriter.

in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-16LE"));

-Kayaman-a at 2007-7-12 15:46:45 > top of Java-index,Java Essentials,Java Programming...
# 5

Hello,

I am in need of you peoples help.

I am using to writhe the UTF-16LE formatted string in to the .txt file and i am using to read the same string.And its working fine.

But now my problem is,after writing into the file if i change a single character then the entire file itself reading as a junk.Is there any limitation that i should not change the UTF-16LE formatted file?

Please anyone help me.

Thank you.

pon_aruna at 2007-7-12 15:46:45 > top of Java-index,Java Essentials,Java Programming...