Error in output while reading a file from mac

I am trying to read file from mac OS.

The code and everything is correct. There is no error while running the program. Whereas, the result is coming with extra data along with the data in the actual file.

Actually my file contains : MADAM RAJ RAM DEVI SEETHA

But the result is coming like this.

{\rtf1\ansi\ansicpg1252\cocoartf1265
{\fonttbl\f0\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\deftab720
\pard\pardeftab720

\f0\fs22 \cf0 MADAM\
RAJ\
RAM\
DEVI\
SEETHA}

Here is the code.

public static void main(String args[]) throws IOException{
        BufferedReader br = null;

        try {

            String sCurrentLine;

            br = new BufferedReader(new FileReader("/Users/satyanarayanagudivada/Desktop/New.txt.rtf"));

            while ((sCurrentLine = br.readLine()) != null) {
                System.out.println(sCurrentLine);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null)br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        } 
Jon Skeet
people
quotationmark

You're reading an RTF (Rich Text Format) document. It does contain all that data - it's just that if you open it in an editor which understands RTF as a format, it will format the text for you using the information rather than displaying it verbatim. It's like viewing the source of a web page instead of the rendered version.

To prove this to yourself, run this from a terminal window:

cat /Users/satyanarayanagudivada/Desktop/New.txt.rtf

It's not clear where you got the file from, but you probably just want to save it as "Plain Text" instead of "Formatted Text".

people

See more on this question at Stackoverflow