我需要将文本文件转换为字符串,并将其作为输入参数(InputStream类型)放入IFile.create(Eclipse)中。
我正在寻找示例或如何实现此操作,但仍然无法弄清楚...需要您的帮助!
仅供测试,我尝试使用以下代码将原始文本文件转换为UTF-8编码。
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();
但是即使最终的*.test.txt文件采用UTF-8编码,其中的字符仍然是损坏的。
IFile
? - Matt Ball