Reputation: 149
I've got this basic program working but it's spitting out a weird answer. When I run the program it gives me:
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350
{\fonttbl\f0\fswiss\fcharset0
Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural
\f0\fs24
\cf0
CIS
260
is
cool.\
Let's
put
another
sentence
in
here.\
Programming
is
problem
driven.}
*
import java.util.Scanner;
import java.io.*;
public class FileIO
{
public static void main(String[] args)
{
File Fred = new File(System.getProperty("user.home"), "mytext.txt");
try
{
Scanner input = new Scanner(Fred);
while (input.hasNext())
{
System.out.println(input.next());
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Upvotes: 0
Views: 2123
Reputation: 1387
It looks like your mytext.txt
file was saved as rich text, instead of plain text, so it contains formatting information as well as the actual content.
Save the text file again as plain text and you should get the result you expect.
Upvotes: 1
Reputation: 1210
How did you create mytext.txt? It looks like you're reading in an RTF file rather than a flat text file. Try recreating mytext.txt with a simple text editor and try it again.
Upvotes: 3