Thread: Storing different things in the same file.

Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1 Storing different things in the same file. 
    Oxygen
    Guest
    Well I'm looking towards storing different things in a file, which I know how to do, I just don't know how to store them on the same line of text in the same file.

    Like..
    Code:
    PlayerName SomethingElseHere
    I would think you would need to use a .cfg file but I don't know how to do that.
    But when you store them in the same line, your operation reads them seperate
    SO my question is.

    How would I store information in the same file on the same line of text, but when I use something that reads from the file, it reads from the same line and uses them seperate.

    Like I want
    "+PlayerName+" is "+SomethingElseHere+".

    Hope you understand me O_O
    I think I lost myself <_<
    Reply With Quote  
     

  2. #2  
     

    Vastiko's Avatar
    Join Date
    Dec 2006
    Posts
    5,700
    Thanks given
    300
    Thanks received
    663
    Rep Power
    5000
    BufferedWriter bw = new BufferedWriter("./test.txt");
    bw.write("yayaya");
    bw.write("\t");//Tabbing
    bw.newLine();
    bw.flush();
    bw.close();

    ?
    Reply With Quote  
     

  3. #3  
    Registered Member
    Core's Avatar
    Join Date
    Sep 2007
    Posts
    4,194
    Thanks given
    11
    Thanks received
    393
    Rep Power
    1985
    Check out NpcHandler and see how autospawn is loaded
    Reply With Quote  
     

  4. #4  
    Oxygen
    Guest
    Code:
    	public boolean loadAutoSpawn(String FileName) {
    		String line = "";
    		String token = "";
    		String token2 = "";
    		String token2_2 = "";
    		String[] token3 = new String[10];
    		boolean EndOfFile = false;
    		int ReadMode = 0;
    		BufferedReader characterfile = null;
    
    		try {
    			characterfile = new BufferedReader(new FileReader("./" + FileName));
    		} catch (FileNotFoundException fileex) {
    			Misc.println(FileName + ": file not found.");
    			return false;
    		}
    		try {
    			line = characterfile.readLine();
    		} catch (IOException ioexception) {
    			Misc.println(FileName + ": error loading file.");
    			return false;
    		}
    		while (EndOfFile == false && line != null) {
    			line = line.trim();
    			int spot = line.indexOf("=");
    
    			if (spot > -1) {
    				token = line.substring(0, spot);
    				token = token.trim();
    				token2 = line.substring(spot + 1);
    				token2 = token2.trim();
    				token2_2 = token2.replaceAll("\t\t", "\t");
    				token2_2 = token2_2.replaceAll("\t\t", "\t");
    				token2_2 = token2_2.replaceAll("\t\t", "\t");
    				token2_2 = token2_2.replaceAll("\t\t", "\t");
    				token2_2 = token2_2.replaceAll("\t\t", "\t");
    				token3 = token2_2.split("\t");
    				if (token.equals("spawn")) {
    					newNPC(Integer.parseInt(token3[0]),
    					Integer.parseInt(token3[1]),
    					Integer.parseInt(token3[2]),
    					Integer.parseInt(token3[3]),
    					Integer.parseInt(token3[4]),
    					Integer.parseInt(token3[5]),
    					Integer.parseInt(token3[6]),
    					Integer.parseInt(token3[7]),
    					Integer.parseInt(token3[8]),
    					GetNpcListHP(Integer.parseInt(token3[0])), true);
    				}
    			} else {
    				if (line.equals("[ENDOFSPAWNLIST]")) {
    					try {
    						characterfile.close();
    					} catch (IOException ioexception) {}
    						return true;
    					}
    				}
    			try {
    				line = characterfile.readLine();
    			} catch (IOException ioexception1) {
    				EndOfFile = true;
    			}
    		}
    		try {
    			characterfile.close();
    		} catch (IOException ioexception) {
    		}
    		return false;
    	}
    Don't understand that. Not one bit.
    Reply With Quote  
     

  5. #5  
    Donator


    Join Date
    Mar 2008
    Posts
    1,945
    Thanks given
    118
    Thanks received
    201
    Rep Power
    2104
    BufferedWriter bw = new BufferedWriter("./test.txt");
    bw.write(playerName);
    bw.write("\t");//Tabbing
    bw.write(somethingelse);
    bw.newLine();
    bw.flush();
    bw.close();
    Attached image
    Reply With Quote  
     

  6. #6  
     

    Vastiko's Avatar
    Join Date
    Dec 2006
    Posts
    5,700
    Thanks given
    300
    Thanks received
    663
    Rep Power
    5000
    Code:
    line = line.trim();
                int spot = line.indexOf("=");
    
                if (spot > -1) {
                    token = line.substring(0, spot);
                    token = token.trim();
                    token2 = line.substring(spot + 1);
                    token2 = token2.trim();
                    token2_2 = token2.replaceAll("\t\t", "\t");
                    token2_2 = token2_2.replaceAll("\t\t", "\t");
                    token2_2 = token2_2.replaceAll("\t\t", "\t");
                    token2_2 = token2_2.replaceAll("\t\t", "\t");
                    token2_2 = token2_2.replaceAll("\t\t", "\t");
                    token3 = token2_2.split("\t");
                    if (token.equals("spawn")) {
                        newNPC(Integer.parseInt(token3[0]),
                        Integer.parseInt(token3[1]),
                        Integer.parseInt(token3[2]),
                        Integer.parseInt(token3[3]),
                        Integer.parseInt(token3[4]),
                        Integer.parseInt(token3[5]),
                        Integer.parseInt(token3[6]),
                        Integer.parseInt(token3[7]),
                        Integer.parseInt(token3[8]),
                        GetNpcListHP(Integer.parseInt(token3[0])), true);
    All it's really doing is splitting the tabs into seperate parts. Which sorts them into an array

    Very simple.
    Reply With Quote  
     

  7. #7  
    Oxygen
    Guest
    Quote Originally Posted by lmctruck30 View Post
    BufferedWriter bw = new BufferedWriter("./test.txt");
    bw.write(playerName);
    bw.write("\t");//Tabbing
    bw.write(somethingelse);
    bw.newLine();
    bw.flush();
    bw.close();
    Perfect. Except how would I load it like
    Code:
    "+playerName+" has "+somethingelse+"


    ---------- Post added at 04:37 AM ---------- Previous post was at 04:15 AM ----------

    bump.
    Reply With Quote  
     

  8. #8  
    Registered Member
    Shamon King's Avatar
    Join Date
    Aug 2007
    Posts
    3,335
    Thanks given
    90
    Thanks received
    228
    Rep Power
    1363
    Quote Originally Posted by lmctruck30 View Post
    BufferedWriter bw = new BufferedWriter("./test.txt");
    bw.write(playerName);
    bw.write("\t");//Tabbing
    bw.write(somethingelse);
    bw.newLine();
    bw.flush();
    bw.close();
    Nope.
    The out come would be.

    Player name
    "tab here"
    something else

    Code:
    bw.write(playerName);
    bw.appened("\t");//Tabbing
    bw.appened(somethingelse);
    bw.newLine();
    bw.flush();
    bw.close();
    something along those lines would get you

    player name "tab here" something else
    Reply With Quote  
     

  9. #9  
    Oxygen
    Guest
    Well How would I make it like that? And have something that reads from it?
    Reply With Quote  
     

  10. #10  
     

    Vastiko's Avatar
    Join Date
    Dec 2006
    Posts
    5,700
    Thanks given
    300
    Thanks received
    663
    Rep Power
    5000
    Quote Originally Posted by Oxygen View Post
    Well How would I make it like that? And have something that reads from it?
    BufferedReader br = new BufferedReader("directory");
    String line = "";

    while ((line = br.readLine()) != null) {
    int index = line.getIndex("has"); //This will return index of h.
    String name = line.substring(0, index);
    String name2 = line.substring(index+3);
    }
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

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


User Tag List

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