I've successfully created an item scanner for my game.
Here is my code:
import java.io.*;
import java.util.*;
public class ItemScanner {
public static void main(String args[]) {
System.out.print("Enter item to find: ");
Scanner sc = new Scanner(System.in);
find(sc.nextLine());
}
public static void find(String delim) {
File dir = new File("accounts");
if (dir.exists()) {
String read;
try {
File files[] = dir.listFiles();
for (int i = 0; i < files.length; i++) {
File loaded = files[i];
if (loaded.getName().endsWith(".txt")) {
BufferedReader in = new BufferedReader(new FileReader(loaded));
StringBuffer load = new StringBuffer();
while ((read = in.readLine()) != null) {
load.append(read + "\n");
}
String delimiter[] = new String(load).split(delim);
if(delimiter.length > 1) {
System.out.println("Found " + (I don't know how to read 1 tab over - 1) + " time(s) in " + loaded.getName() + "!");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("error: dir wasn't found!");
}
}
}
I'm on the last step of making my life easier when it comes to finding how many of this item the player has.
here's the scenario:
Search Item: 6570
Found [x] time(s) in Account.txt!
This is how the layout of the items are
account-item = 6570 1
It's read like this: 6570 is the item, then [tab] , 1 equals how much of the item that user has.
So if it says
account-item = 6570 24
The user has 24 of that item.
Problem:
I simply do not know how to return the value of the item from 1 tab over.
So if I search for 6570, and if it is found, how would i get the amount of the item being found? Here's my code to return the items
String delimiter[] = new String(load).split(delim);
if(delimiter.length > 1) {
System.out.println("Found " + (I don't know - 1) + " time(s) in " + loaded.getName() + "!");
}