Results 1 to 2 of 2
  1. #1
    daoping is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Question Taking a line from a text file if it contains the specified text

    Hi Java developers,

    I'm currently modding MineCraft (just for fun :)) and I'm stuck with a problem:
    How do I copy a line of a .txt file which contains the specified text? (Hashset)

    Example:

    In my items.txt file:
    Java Code:
    cobblestone:4
    smoothstone:1
    sand:12
    grass:2
    water:8
    In my code:
    Java Code:
    if (items.contains("cobblestone"))
    {
        String blabla = //Code to copy cobble out of the .txt file;
        String[] k = blabla.split(":");
        int itemId = Integer.Parse(k[0]);
        player.dropPlayerItemWithoutDelay(new ItemStack(itemId, 64, 0), false);
    }
    So basically what I need to know is:
    -How do I copy a specific line of .txt
    -How do I get the line number of a .txt which contains a specific text

  2. #2
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default

    You could use a Scanner to load the file and parse through each line checking to see if "cobblestone" exists in each. And keep a counter to know how many lines you've gone through.

Similar Threads

  1. Stepping through a text file line by line
    By evanlivingston in forum New To Java
    Replies: 10
    Last Post: 01-29-2011, 04:30 AM
  2. Replies: 8
    Last Post: 12-28-2010, 02:24 PM
  3. Inserting line into text file
    By Onra in forum Advanced Java
    Replies: 5
    Last Post: 09-14-2010, 11:21 AM
  4. Help! - How to insert a new line to a text file
    By matpj in forum New To Java
    Replies: 13
    Last Post: 02-24-2010, 05:28 PM
  5. Saving To A New Line Using A Text File
    By jadaleus in forum Advanced Java
    Replies: 10
    Last Post: 10-24-2008, 07:21 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
  •