📄 locale.java
字号:
import java.io.InputStream;
import java.io.IOException;
import java.util.Hashtable;
public class Locale
{
private final static Locale instance = new Locale();
private static Hashtable map;
public Locale()
{
//#ifdef debug
System.out.println("Loading resources from locale.txt");
//#endif
map = new Hashtable();
// load up the resource strings
InputStream is = null;
try
{
is = this.getClass().getResourceAsStream("locale.txt");
boolean done = false;
byte buffer[] = new byte[1];
StringBuffer line = new StringBuffer();
// read a line and add the entries
while (!done)
{
int bytesRead = is.read(buffer);
if (bytesRead != -1)
{
if (buffer[0] == '\n')
{
String s = line.toString().trim();
// we ignore lines starting with #, or if they dont have a
// = in them, or if the length is smaller than the min of
// 3 chars (ie. 'a=b')
if (!s.startsWith("#") && s.length() > 2 &&
s.indexOf('=') != -1)
{
String key = s.substring(0, s.indexOf('=')).trim().toLowerCase();
String value = s.substring(s.indexOf('=')+1).trim();
map.put(key, value);
//#ifdef debug
System.out.println("Loading setting: " + key + "='" + value + "'");
//#endif
}
line.setLength(0);
}
else
line.append((char)buffer[0]);
} else
done = true;
}
}
catch(IOException io)
{
System.out.println("Error loading resources: " + io);
}
finally
{
try
{
is.close();
}
catch(IOException io) { }
}
}
public static String getString(String key)
{
String s = (String)map.get(key.toLowerCase());
if (s != null) return s;
//#ifdef debug
System.out.println("Attempt to get an unknown defined resource string: " + key);
//#endif
return key;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -