首页 > 代码库 > 【java】获取当前环境属性及编码乱码示例

【java】获取当前环境属性及编码乱码示例

技术分享
 1 package 字符编码;
 2 
 3 import java.io.File;
 4 import java.io.FileOutputStream;
 5 import java.io.IOException;
 6 import java.io.OutputStream;
 7 import java.io.UnsupportedEncodingException;
 8 
 9 public class TestGetProperties {
10     public static void main(String[] args) throws UnsupportedEncodingException, IOException {
11         System.getProperties().list(System.out);//输出当前环境属性
12         File file=new File("D:"+File.separator+"test.txt");
13         OutputStream out=new FileOutputStream(file);
14         out.write("黄山黄河长江长城".getBytes("UTF-8"));//无乱码
15         out.write("黄山黄河长江长城".getBytes("ISO8859-1"));//有乱码
16         out.close();
17     }
18 }
View Code

 

【java】获取当前环境属性及编码乱码示例