java——输出到文件

2019年2月23日18:33:33 发表评论 1,274 views
/**
 * Created by xabcd on 2019/2/23.
 */
import java.io.*;
public class EcodingDemo {
    public static void main(String args[])
        throws Exception
    {
        //在这里将字符串通过getBytes()方法,编码成GB2312
        byte b[] = "大家一起来学Java语言".getBytes("GB2312");
        OutputStream out = new FileOutputStream(new File("c:\\ecoding.txt"));
        out.write(b);
        out.close();
        System.out.println("运行OK");
    }
}


结果:
创建一个文件并放入那句话

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: