Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Display Rich Text Format (.rtf) File(Display Simplified Chinese Characters in an .rtf File?)
Display Rich Text Format (.rtf) File [message #1717574] Mon, 14 December 2015 23:54
Arthur Chan is currently offline Arthur ChanFriend
Messages: 44
Registered: September 2015
Hi, I have a .rtf-file containing simplified Chinese characters. It was created in a Windows-10 env.

I am running eclipse Mars.1 in Windows-7 env. My Firefox and MS Word and WordPad can display the original .rtf-file, but eclipse is not.

My InputStreamReader and OuputStreamWriter are configured to read UTF-8, seems like it is not UTF-8

Is this an issue with eclipse or is it my coding, or an issue with UTF-8

This is what pops up in the console:
1 {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fprq2\fcharset134 SimSun;}}
2 {\*\generator Riched20 6.3.9600}{\*\mmathPr\mnaryLim0\mdispDef1\mwrapIndent1440 }\viewkind4\uc1
3 \pard\nowidctlpar\sa200\sl276\slmult1\b\f0\fs40\lang2052\'ce\'d2\'cf\'eb\'c2\'f2\'d7\'d4\'d0\'d0\'b3\'b5\par
4 \'b5\'d8\'cc\'fa\par
5 \'b8\'df\'cc\'fa\par
6 \'b9\'ab\'b9\'b2\'c6\'fb\'b3\'b5\'d5\'be\'d4\'da\'c4\'c7\'a3\'bf\par
7 \'bc\'fb\'bc\'d2\'c8\'cb\par
8 \par
etc etc

And this is the code:
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ReadWriteUTF8Files {
	public static void main(String[] args) throws IOException{

		// Inbound files deposited in this directory...
		Path inPath = Paths.get("C:", "Users", "ARTHUR", "eclipse", "textFiles", "Îĵµ.rtf");
		String strInPath = inPath.toString();
		// Processed files to be archived to this directory...
		Date todaysDate = new Date();
		DateFormat df7 = new SimpleDateFormat("yyyyMMMdd-HHmmss");
		String strDateTime = df7.format(todaysDate);
		final String strArchive = ("C:/Users/ARTHUR/eclipse/ArchivedFiles/Îĵµ" + strDateTime + ".rtf");
		File inFile = new File(strInPath);
		Boolean canRead = inFile.canRead();
		String aLine = null;
		if (canRead) {
			// FileReader reads from this text file in UTF-8 encoding
			Reader readUTF8 = new InputStreamReader(new FileInputStream(strInPath), "UTF-8");
			BufferedReader br = new BufferedReader(readUTF8);
			LineNumberReader lnr = new LineNumberReader(br);
			//  writes to this file in default encoding
			Writer writeUTF8 = new OutputStreamWriter(new FileOutputStream(strArchive), "UTF-8");
			BufferedWriter bw = new BufferedWriter(writeUTF8);
			while ((aLine = lnr.readLine()) != null) {
				int lineNo = lnr.getLineNumber();
				bw.write(lineNo + "\t" + aLine + "\r\n");		//	If "\r\n" does not work (might be a file from Unix or Mac), then try bw.newLine() or bw.newLine(\r\n);
				System.out.println(lineNo + "\t" + aLine);
			// close the outside object lnr, no need to close inside objects
			// if you don't close bw, it won't flush to file and you get an empty file
		} else {
			System.out.println("File path does not exist " + strInPath);
Previous Topic:Android SDK
Next Topic:Package Separate
Goto Forum:

Current Time: Wed Aug 05 20:12:47 GMT 2020

Powered by FUDForum. Page generated in 0.03342 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top