请参阅将字母转换为数字
在文件test.in.rtf
中,我输入了“abcd”。但是,当我运行程序时,我??? ??????????? ???????? plus maybe a few more
进入test.out.rtf
. 为什么是这样?我错过了什么吗?
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Test {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("test.in.rtf"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("test.out.rtf")));
StringTokenizer st = new StringTokenizer(f.readLine());
StringBuilder sb = new StringBuilder();
for (char c : st.nextToken().toCharArray()) {
sb.append((char)(c - 'a' + 1));
}
out.println(sb); // output result
out.close(); // close the output file
System.exit(0);
}
}