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:
Code:
cobblestone:4
smoothstone:1
sand:12
grass:2
water:8
In my code:
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