关闭

JAVA程序:UTF码进行文件的读写

388人阅读 评论(0) 收藏 举报

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class TestStream {

 public static void main(String[] args) {
  
  try{
   FileOutputStream fileOutputStream = new FileOutputStream("f://001.txt");
   BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
   DataOutputStream dataOutputStream = new DataOutputStream(bufferedOutputStream);
   
   dataOutputStream.writeUTF("中国");
   dataOutputStream.writeUTF("美国");
   dataOutputStream.writeUTF("日本");
   dataOutputStream.close();
   
   FileInputStream fileInputStream = new FileInputStream("f://001.txt");
   BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
   DataInputStream dataInputStream = new DataInputStream(bufferedInputStream);
   
   System.out.println(dataInputStream.readUTF());
   System.out.println(dataInputStream.readUTF());
   System.out.println(dataInputStream.readUTF());
   
  }catch(Exception e){
   e.printStackTrace();
  }
 }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:33494次
    • 积分:515
    • 等级:
    • 排名:千里之外
    • 原创:17篇
    • 转载:7篇
    • 译文:0篇
    • 评论:5条
    文章存档
    最新评论