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; } }




Reply With Quote