java io package classes supporting encoding "ISO 8859_1"
807569May 23 2006 — edited May 30 2006I have to read/write file in various languages.I am able to read but not able to modify & then write back(it sholud have writing feature in that).
Code for reading/writing is working fine in .net but not in java.
Please provide me solution or java is uncapable of doing this.
We are not having proper supporting classes.
for Reading:
BufferedReader rdr = new BufferedReader(new InputStreamReader (new FileInputStream (filePath),
"ISO-8859-1"));
But for writing i don't have any good option.
In .Net its like :
private void button1_Click(object sender, System.EventArgs e)
{
//Creating an instance of Encoding Class based on locale
System.Text.Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
//Open a reader to read the data from text file based on given encoding.
StreamReader reader = new StreamReader("D:\\UnicodeTxt.txt",encoding);
string toTranslate = reader.ReadToEnd();
reader.Close();
richTextBox1.Text = toTranslate;
//Print in debug mode.
Debug.WriteLine("Before Translation");
Debug.WriteLine(toTranslate);
//ASCIIEncoding encoding = new ASCIIEncoding();
//UTF8Encoding encoding = new UTF8Encoding();
//UnicodeEncoding encoding = new UnicodeEncoding();
//Convert the string into byte array
Byte[] byteArray = encoding.GetBytes(toTranslate);
for(int x=0; x< byteArray.Length; x++)
{
//Print the byte in debug window.
Debug.WriteLine(byteArray.GetValue(x).ToString());
}
Debug.WriteLine("After Translation");
//Convert each byte into appropriate character
Char[] charArray = encoding.GetChars(byteArray);
//Write each character to a new File based on the same encoding instance.
StreamWriter writer = new StreamWriter("D:\\UnicodeTxt1.txt",false,encoding);
for(int x=0; x<charArray.Length ; x++)
{
//Write into the writer, which inturns writes back into file.
writer.Write(charArray.GetValue(x).ToString());
//Print in Debug window.
Debug.Write(charArray.GetValue(x).ToString());
}
//Flush the output to the file, and close the writer.
writer.Flush();
writer.Close();
label1.Text = "Translation Completed Successfully";
}
I am looking for same functionality in java .
How can i get it pleasehelp he to get this done in java.
some trails are here:
if (content instanceof ByteBlock) {
byte[] blk = ((ByteBlock) content).bytes();
Encoding sjis = Encoding.getEncoding("ISO-8859-1");
// String unicodeString = sjis.getString(shift_jis_string);
if (blk != null)
{
FileOutputStream fs = new FileOutputStream
(path, append != null && append.booleanValue());
// StreamTokenizer output = new StreamTokenizer(fs,"ISO-8859-1");
//static FastWriter FastWriter.getInstance(Broker broker, java.io.OutputStream out, java.lang.String encoding)
//Get a new FastWriter
fs.write (blk, 0, blk.length);
fs.close();
// Open a TextWriter for the appropriate file
/* {
char[] c = new char[blk.length];
for (int i = 0; i < blk.length; i++) {
c[i] = (char)blk;
} */
//byte[] bytes = (new String(c, 0, c.length)).getBytes("ISO-8859-1");
// String roundTrip = FileUtils.fileContent (path).toString();
// bw.write (c, 0, c.length);
//bw.close();
// }
}
}
Thanks
Vijendra