import java.io.*;public class GB2312Output {public static void main(String[] args) {try {// 创建文件输出流FileOutputStream fos = new FileOutputStream("output.txt");// 创建GB2312编码的输出流写入器OutputStreamWriter osw = new OutputStreamWriter(fos, "GB2312");// 创建缓冲输出流BufferedWriter writer = new BufferedWriter(osw);// 要输出的文本String text = "你好,世界!";// 将文本写入输出流writer.write(text);// 关闭流writer.close();osw.close();fos.close();System.out.println("文本已成功输出为GB2312格式。");} catch (IOException e) {e.printStackTrace();}}
}