在Java中,可以使用字符流和字节流来输出中文字符。
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
writer.write("你好,世界!");
writer.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
OutputStream outputStream = new FileOutputStream("output.txt");
outputStream.write("你好,世界!".getBytes("UTF-8"));
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
请注意,为了正确地输出中文字符,需要指定正确的字符编码,例如UTF-8。