Thread: loading file gone wrong?

Results 1 to 5 of 5
  1. #1 loading file gone wrong? 
    Old Webdeveloper
    Dondxon's Avatar
    Join Date
    Aug 2011
    Posts
    1,144
    Thanks given
    209
    Thanks received
    108
    Rep Power
    65
    Hey.

    i have this
    Code:
    	public BufferedReader getInfo() {
    		try {
    			BufferedReader data = new BufferedReader(new FileReader("./Data/characters/" + c.playerName + ".txt"));
    			return data;
    		} catch(Exception e) {
    			e.printStackTrace();
    			return null;
    		}
    	}
    in CharBackupHandler.java

    Next i have a query:
    Code:
    query("INSERT INTO `users` (`id`, `username`, `date`, `characterfile`) VALUES (NULL, '"+c.playerName+"', CURRENT_TIMESTAMP, '"+getInfo()+"');");
    And when i save this it appears as:


    Why doesnt this:

    not print out as your character file????

    Please help
    Do you need any PHP work done? Or are you looking for RSPS integrations? click herel.

    Vouches

    Reply With Quote  
     

  2. #2  
    Donator


    Join Date
    Sep 2007
    Age
    27
    Posts
    2,426
    Thanks given
    125
    Thanks received
    505
    Rep Power
    386
    This is happening because it's attempting to serialize an instance of BufferedReader.
    Due to this class not overriding toString(), it's then simply outputting the class name followed by @ and the memory address of the instance. I think what you were hoping to do was output the contents of the .txt file, correct?
    Reply With Quote  
     

  3. #3  
    Registered Member
    TheChosenOne's Avatar
    Join Date
    Jan 2013
    Posts
    967
    Thanks given
    47
    Thanks received
    161
    Rep Power
    366
    What Avatar Realms said.
    To read the content, you'll need one (or more) of the methods which you can find here: BufferedReader (Java Platform SE 6).
    Most notable are readLine, which reads a line of text in your file and outputs it as a String.
    The other is read(char[], int, int) which reads a number of bytes into the buffer you supply the method with.
    Reply With Quote  
     

  4. Thankful user:


  5. #4  
    Super Donator

    Batukka's Avatar
    Join Date
    Oct 2011
    Posts
    2,433
    Thanks given
    86
    Thanks received
    342
    Rep Power
    496
    Code:
    public String getInfo() {
    		try {
                            StringBuilder stringReturn = new StringBuilder();
                            String readLine = null;
    			BufferedReader data = new BufferedReader(new FileReader("./Data/characters/" + c.playerName + ".txt"));
                            while((readLine = data.readLine()) != null){
                                     stringReturn.append(readLine+"\n");
                            }
    			return stringReturn.toString();
    		} catch(Exception e) {
    			e.printStackTrace();
    			return null;
    		}
    	}
    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    Old Webdeveloper
    Dondxon's Avatar
    Join Date
    Aug 2011
    Posts
    1,144
    Thanks given
    209
    Thanks received
    108
    Rep Power
    65
    Quote Originally Posted by Bitj View Post
    Code:
    public String getInfo() {
    		try {
                            StringBuilder stringReturn = new StringBuilder();
                            String readLine = null;
    			BufferedReader data = new BufferedReader(new FileReader("./Data/characters/" + c.playerName + ".txt"));
                            while((readLine = data.readLine()) != null){
                                     stringReturn.append(readLine+"\n");
                            }
    			return stringReturn.toString();
    		} catch(Exception e) {
    			e.printStackTrace();
    			return null;
    		}
    	}
    Worked thansk mate
    Do you need any PHP work done? Or are you looking for RSPS integrations? click herel.

    Vouches

    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. items gone wrong
    By pkhonor in forum Help
    Replies: 3
    Last Post: 08-19-2009, 07:32 AM
  2. Loading Files (.txt)
    By Swarfega in forum Help
    Replies: 8
    Last Post: 08-10-2009, 08:07 PM
  3. slayer gone wrong
    By pkhonor in forum Help
    Replies: 8
    Last Post: 08-04-2009, 01:58 AM
  4. Have I Gone Wrong!
    By Zena in forum Help
    Replies: 4
    Last Post: 05-31-2009, 06:52 PM
  5. Mqo could load file rep+
    By Arvid in forum Help
    Replies: 0
    Last Post: 11-23-2008, 03:19 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
  •