我认为您是 Java 编程语言(面向对象)的新手,所以您犯了这个错误。
你应该把这些东西放在函数里面。
所以,它可能看起来像:
package org.maple.mapleshot;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JOptionPane;
public class CheckSettings {
public void check(){
BufferedReader reader;
File f = new File (System.getProperty("user.home") + "/Desktop/Settings.txt");
String line = null;
if (f.exists()) {
try {
reader = new BufferedReader(new FileReader(System.getProperty("user.home") + "/Desktop/Settings.txt"));
line = reader.readLine();
} catch (IOException e2) {
// TODO Auto-generated catch block
//e2.printStackTrace();
JOptionPane.showMessageDialog(null, "Error Code: Bx001", "Error", 0);
}
//System.out.println(line);
Shared.enableHotKey = line.substring (0, line.indexOf("!"));
Shared.key1 = line.substring(line.indexOf("!") + 1, line.indexOf("@"));
Shared.key2 = line.substring(line.indexOf("@") + 1, line.indexOf("#"));
Shared.key3 = line.substring(line.indexOf("#") + 1, line.indexOf("$"));
Shared.startUpMessage = line.substring(line.indexOf("$") + 1);
System.out.println(Shared.enableHotKey + " " + Shared.key1 + " " + Shared.key2 + " " + Shared.key3 + " " + Shared.startUpMessage);
} else {
Shared.startUpMessage = "true";
}
}
}
不要担心这些事情。只要多练习,你就会对java更加熟悉。