Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    335
    Rep Power
    4

    Default

    Ah yes! To append data to a file instead of overwriting it construct the FileOutputStream with a boolean value.

    This code appends data to a file:
    Java Code:
    FileOutputStream fos = new FileOutputStream("file.txt", true);

    These codes do not:
    Java Code:
    FileOutputStream fos = new FileOutputStream("file.txt", false);
    Java Code:
    FileOutputStream fos = new FileOutputStream("file.txt");
    Regards.

  2. #22
    Join Date
    Oct 2010
    Posts
    35
    Rep Power
    0

    Default

    Have i constructed my instance variables right? i have a text called id.txt that has last name: first name: rounds played: rounds won:
    so did i do that right?

    Java Code:
    while(inScan.toString() != null ){
                        
                        String pfileName = Id + ".txt";
                        Scanner pScan = new Scanner(new File(pfileName));
                      lastName = inScan.next();
                      firstName = inScan.next();
                      roundsPlayed = inScan.nextInt();
                      roundsWon = inScan.nextInt();
                      
                     
                     }
                }
         
                     
                     // need while loop 
    
              
        public boolean valid() throws FileNotFoundException {
                            
                
                return isValid;
        
        
        }
    okay so do i put
    Java Code:
    FileOutputStream fos = new FileOutputStream("file.txt", true);
    into my
    Java Code:
    public boolean valid() throws FileNotFoundException {
                            
                
                return isValid;
        
        
        }
    ?

  3. #23
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    335
    Rep Power
    4

    Default

    You can use a Scanner to read in the data if you wish though the code you have provided will not work. There is some good examples here to show you how.

    I would love to help you further, but I need sleep. Hope it all goes well for you.

    Regards.

  4. #24
    Join Date
    Oct 2010
    Posts
    35
    Rep Power
    0

    Default

    Thank you Ronin i will add to your rep :)

  5. #25
    semitrix is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default

    hey basketball, don't know if you remember me but i finally got mine to work. if you look at the book section 4.10 on files, it helps a lot! I was able to do it by just reading through that. Hope this helps !

  6. #26
    Join Date
    Oct 2010
    Posts
    35
    Rep Power
    0

    Default

    hey man... i have been trying to use that here and there but i was still getting stuck..idk glad you got it man... gonna be a long night :confused:

  7. #27
    Join Date
    Oct 2010
    Posts
    35
    Rep Power
    0

    Default

    okay now i am moving a little further..or maybe i am not but which was do you guys this is the right approach.. this way
    Java Code:
    public boolean valid() throws FileNotFoundException { 
                    
                    String pfileName = Id + ".txt";
                    Scanner pScan = new Scanner(new File(pfileName));
                    Scanner id = new Scanner ("id.txt");
                    
                
                                    
                                    
                        return isValid;
                
                
                }
    or this way
    Java Code:
    public void setValid(String lastN, String Id1, String firstN, int rp, int rw) throws FileNotFoundException // or this way
                {
                    lastName = lastN;
                    firstName = firstN;
                    roundsPlayed = rp;
                    roundsWon = rw;
                    Id = lastN + firstN + rp + rw;
                    String pFileName = Id + ".txt";
                    Scanner pScan = new Scanner(new File(pFileName));
                    
                    
                }
    remember in my assig.java i have it calling this method
    Java Code:
     if (p.valid())
                {
                 System.out.println("Hello " +  theId);
                 System.out.println("\nThank you for coming back to the Scrambler");

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Need help running 2 frames at the same time.
    By Nuclear Mosquito in forum AWT / Swing
    Replies: 4
    Last Post: 07-03-2010, 06:11 PM
  2. Running thread a second time
    By Fleur in forum New To Java
    Replies: 18
    Last Post: 11-17-2009, 12:57 PM
  3. Replies: 1
    Last Post: 06-30-2009, 02:32 PM
  4. Improve the slow running time
    By coolFrenzi in forum Advanced Java
    Replies: 1
    Last Post: 04-12-2009, 12:15 PM
  5. Calculating the Running time
    By JordashTalon in forum New To Java
    Replies: 2
    Last Post: 02-13-2009, 10:32 PM

Posting Permissions

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