Results 1 to 8 of 8

Thread: Remembering

  1. #1
    whosadork is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default Remembering

    How do I have eclipse remember something that is entered by the user, then when the program terminates, and you compile it again then eclipse remembers it..........

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,456
    Rep Power
    25

    Default

    One way would be to write it to a file.
    You need to fully state your problem. I'm not sure if you are talking about settings for the IDE or data for a java program.

  3. #3
    whosadork is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default

    i'm talking about data, how to store it for another time, and if the user commands for the data then he gets it.
    like he put in data and terminated the program, then the compiler remembers the data and next time the program is run and the user askes for the data he gets it.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    As Norm stated above, you will have to write the information to a file and then read it back in when the program restarts. There are many ways to do this, and you can learn about a few of them at the Sun IO tutorials:
    Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)
    The Java™ Tutorials

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,456
    Rep Power
    25

    Default

    There are many code examples on the forum. Use Search for write for example

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Another way to store data that immediately comes to mind is to use Properties. I believe that these should not be used to store all kinds of data, but rather should be used to store the state of the program or in other words program "properties" (makes sense, doesn't it?).

    You can read up on them here:
    Properties (The Java™ Tutorials > Essential Classes > The Platform Environment)

  7. #7
    whosadork is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default

    thanks man, the only problem is that in the tutorial it shows you a class how to call in the data.
    so if you guys cant help me on it becouse its allready made, and i didn't make it, it'll be cool.
    i cant get it right, it just wont call in my notepad text.

    Java Code:
    package ReadFile;
    
    import java.io.*;
    class FileRead 
    {
       public static void main(String args[])
      {
          try{
        // Open the file that is the first 
        // command line parameter
        FileInputStream fstream = new FileInputStream("Readme.txt");
        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        //Read File Line By Line
        while ((strLine = br.readLine()) != null)   {
          // Print the content on the console
          System.out.println (strLine);
        }
        //Close the input stream
        in.close();
        }catch (Exception e){//Catch exception if any
          System.err.println("Error: " + e.getMessage());
        }
      }
    }
    Error: Readme.txt (The system cannot find the file specified)

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,456
    Rep Power
    25

    Default

    Is the txt file in the same folder as where the java command is executed? How are you executing the java command?
    Open a command prompt window, change directory to the folder with the txt file and the ReadFile directory file and enter the java command. The ReadFile directory must contain the FileRead.class file.

    Your problem is probably with the classpath and the package path for your program. The class file must be in the folder as per the package statement in your program. The txt file must be in the current directory when you execute the program.
    To simplfy it so that both files can be in the same folder, remove the package statement from your program.

Posting Permissions

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