[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[jdt-dev] Reading/Writing UTF-8 fromat
|
Firstly, I'm not sure that this message in its correct place ... so I'm
sorry if there is a mistake .
i need to read and write UTF8 text format but i couldn't do that by
using this code (reading process is correct but writing is wrong)... can
you help me.
remark :
if the UTF8 file was short writing process done well, but if it was big writing process not working .
--
Best Regards تحياتي
Muhammad Bashir Al-Noimi محمد بشير النعيمي
مدونتي My Blog
http://www.hali-sy.net/bashir
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
public class Po2Tab {
private List lst;
private String Path;
private StringBuffer Buffer;
// private static final String NEW_LINE = System.getProperty("line.separator");
public Po2Tab(String PoFilePath){
Path = PoFilePath;
}
public String getString() {
// return lst.toString().replace(",", "");
return Buffer.toString();
}
public List getList() {
return lst;
}
public void OpenFromFile(String Path){
try {
BufferedReader in = new BufferedReader(new FileReader(Path));
lst = new ArrayList();
String temp,temp2;
int x = 0;
while( ( temp = in.readLine()) != null) {
temp2 = new String(temp.getBytes(),"UTF-8");
if (temp2.contains("msgid \"")) {
x++;
System.out.println("Adding word Nr.:"+String.valueOf(x));
temp2 = temp2.toLowerCase();
temp2 = temp2.replace("msgid \"", "");
temp2 = temp2.replace("\"", "");
}else if(temp2.contains("msgstr \"")){
x++;
temp2 = temp2.toLowerCase();
temp2 = temp2.replace("msgstr \"", "\t");
temp2 = temp2.replace("::", "\\n");
temp2 = temp2.replace("¡", "\\n");
temp2 = temp2.replace("\"", "");
temp2 += "\n";
}
else{
temp2="";
}
if(temp2 != "")
{
lst.add(temp2);
Buffer.append(temp2);
}
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void SaveToFile(String Path){
try {
RandomAccessFile out = new RandomAccessFile(Path,"rw");
out.writeUTF(getString());
// out.writeUTF(Buffer.toString());
out.close();
lst.clear();
Buffer = null;
// for (int i = 0; i < lst.size()-1; i++) {
// temp = new String(lst.get(i).toString().getBytes(),"UTF-8");
// out.writeUTF(temp);
// out.writeUTF(lst.get(i).toString().replace(",", ""));
// out.writeChars(temp);
// out.write();
// }
} catch (Exception e) {
e.printStackTrace();
}
}
public int getFileLenght() {
return lst.size();
}
}