package macroreader;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class MacroReader {
public static Macro[] macroArray = new Macro[20];
public static int macroID;
public static BufferedReader br;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new FileReader("Macros.txt"));
String currentLine;
while((currentLine = br.readLine()) != null) {
if(currentLine.equalsIgnoreCase("#newmacro")) {
br.mark(1000);
createMacro();
br.reset();
}
}
if (br != null) {
br.close();
}
}
public static void createMacro() throws IOException {
String currentLine;
macroID = getEmptyMacro();
while((currentLine = br.readLine()) != null && !currentLine.equalsIgnoreCase("#newmacro")) {
macroArray[macroID].readMacro(currentLine);
}
macroArray[macroID].inUse = true;
macroArray[macroID].printData();
}
public static int getEmptyMacro() {
for(int i = 0; i < macroArray.length; i++) {
if(!macroArray[i].inUse) {
return i;
}
}
return 0;
}
}
而不是将从文件读取器读取的值分配给数组中的指定对象,在本例中为“macroID”,而是将值分配给数组中的所有对象
现在刚刚在整个文件中进行了编辑,但问题在于 createMacro() void
这是我的宏课
package macroreader;
public class Macro {
public static String key;
public static String[] commands = new String[20];
public static boolean inUse;
public static void readMacro(String input) {
if (!input.equals("")) {
if (input.startsWith("key = ")) {
key = input.substring(6);
System.out.println("Key Value for Macro set to " + key);
} else {
for (int i = 0; i < commands.length; i++) {
if (commands[i] == null) {
commands[i] = input;
System.out.println("Command [" + input + "] assigned");
break;
}
}
}
}
}
public static void printData() {
System.out.println("Macro Key: " + key);
for(int i = 0; i < commands.length; i++) {
if(commands[i] != null) {
System.out.println(commands[i]);
}
}
}
}