Results 1 to 7 of 7

Thread: [RESOLVED] Cannot find symbol class TextReader (even though it's imported)

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    38

    Resolved [RESOLVED] Cannot find symbol class TextReader (even though it's imported)

    I just started working on a personal project in Java. I didn't learn about reading and writing to files in the class I took but I'm reading a book online about it. I'm pretty sure I'm doing it right, but it keeps throwing an error at me.

    Code:
    import java.io.*;
    import java.util.*;
    /**
     * Controls the saving, loading, and handling of arrays with information.
     * 
     * @author Nicholas Leveillee
     * @version May 11, 2010
     */
    public class GameFunctions
    {
        
        /**
         * Constructor for objects of class GameFunctions
         */
        public GameFunctions()
        {
            
        }
        
        //This method prompts for the current Operating System
        public void learnOS()
        {
            int ans = 0;
            Scanner input = new Scanner(System.in);
            if(ans>3 || ans <1){
                System.out.println("What is your operating System? (1) Windows (2) Macintosh (3) UNIX/Linux variants");
                System.out.print("Enter the number: ");
                ans = input.nextInt();
            }
            System.out.println("Thank you!");
            //The next if block changes the numeric answer to a string
            String oS = null;
            if(ans == 1){
                oS = "Win";
            }
            else if(ans == 2){
                oS = "Mac";
            }
            else if(ans == 3){
                oS = "Lin";
            }
            //Need to write to a text file, in the same directory.
            PrintWriter sys;
            try{
                sys = new PrintWriter(new FileWriter("system.txt"));
            }
            catch (IOException e){ //Exit if there is an error
                System.out.println("Error: " + e);
                return;
            }
            try{
                sys.print(oS);
            }
            finally{
                sys.close();
            }
        }
        
        //This method returns the operating system, for use in other classes
        public String getOS()
        {
            String oS = null;
            //Setup a file reader and read the first line of system.txt
            TextReader sys; //ERROR HERE:cannot find symbol - class Text Reader
            try {
                sys = new TextReader(new FileReader("system.txt"));
            }
            catch(FileNotFoundException e){
                return;
            }
            try{
                oS = sys.getln;
            }
            catch(IOException e){
                System.out.println("Error: " + e.getMessage());
            }
            finally{
                sys.close();
            }
            return oS;
        }
    }
    I use VB 6. I've been programming since September 2008.

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Cannot find symbol class TextReader (even though it's imported)

    As far as I can tell, TextReader is not part of java.io or java.util, so the error is correct.

    I would recommend using FileInputStream and FileOutputStream to read and write files in java.

    Here is an example of FileInputStream: http://www.java-tips.org/java-se-tip...e-in-java.html

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    38

    Re: Cannot find symbol class TextReader (even though it's imported)

    I'm completely lost. I went by the book which says TextReader, but that apparently doesn't exist. The example you provided only seems to work with bits, I'm trying to read a String.
    I'm looking on the java site, but it's not helping me.
    I use VB 6. I've been programming since September 2008.

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Cannot find symbol class TextReader (even though it's imported)

    Sorry, what do you mean? The example I linked to reads in a text file and displays the string contents of each line in the file.

    Are you receiving an error while using the FileInputStream?

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    38

    Re: Cannot find symbol class TextReader (even though it's imported)

    Yeah, I couldn't find a method that would read the contents correctly. The only semi-appropriate one was .read() but that gets an int value according to the compiler and oS is a string.
    I use VB 6. I've been programming since September 2008.

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Cannot find symbol class TextReader (even though it's imported)

    look for some samples using the java.util.Scanner class. it's close to the way .Net handles IO reading
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    38

    Re: Cannot find symbol class TextReader (even though it's imported)

    I found an example using Scanner in the book. (hopefully it works right)
    I'll post back any problems or mark as resolved when I try it after I get home.
    Thanks.
    I use VB 6. I've been programming since September 2008.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width