Results 1 to 2 of 2
- 02-27-2011, 11:32 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 1
- Rep Power
- 0
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:
In my code:Java Code:cobblestone:4 smoothstone:1 sand:12 grass:2 water:8
So basically what I need to know is: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); }
-How do I copy a specific line of .txt
-How do I get the line number of a .txt which contains a specific text
- 02-28-2011, 05:30 PM #2
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
-
Stepping through a text file line by line
By evanlivingston in forum New To JavaReplies: 10Last Post: 01-29-2011, 04:30 AM -
Reverse search a Text file from last line to top line
By Jman85 in forum New To JavaReplies: 8Last Post: 12-28-2010, 02:24 PM -
Inserting line into text file
By Onra in forum Advanced JavaReplies: 5Last Post: 09-14-2010, 11:21 AM -
Help! - How to insert a new line to a text file
By matpj in forum New To JavaReplies: 13Last Post: 02-24-2010, 05:28 PM -
Saving To A New Line Using A Text File
By jadaleus in forum Advanced JavaReplies: 10Last Post: 10-24-2008, 07:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks