使用静态块。(但是,将流声明为静态变量不是一个好主意。深入了解资源管理。)
private static char[] alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
private static StringBuilder partialSolution = new StringBuilder();
private static File fout = new File("out.txt");
private static FileOutputStream fos;
private static BufferedWriter bw;
static {
try {
fos = new FileOutputStream(fout);
bw = new BufferedWriter(new OutputStreamWriter(fos));
} catch (IOException e) {
e.printStackTrace();
}
}