在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。