I need to convert a text file to String, which finally I have to put as input parameter (type InputStream) in IFile.create (Eclipse) file. Look for an example or how to do it, but you still cannot understand ... your help is needed!
just for testing, I tried to convert the original text file to UTF-8 encoded with this code
FileInputStream fis = new FileInputStream(FilePath); InputStreamReader isr = new InputStreamReader(fis); Reader in = new BufferedReader(isr); StringBuffer buffer = new StringBuffer(); int ch; while ((ch = in.read()) > -1) { buffer.append((char)ch); } in.close(); FileOutputStream fos = new FileOutputStream(FilePath+".test.txt"); Writer out = new OutputStreamWriter(fos, "UTF8"); out.write(buffer.toString()); out.close();
but I even thought that the final * .test.txt file is UTF-8 encoded, the characters inside are corrupted.
java eclipse encoding unicode utf-8
Jackbauer
source share