JAVA之输入输出流(zip未更新)

FileWriter FileReader

public class test {
	public static void main(String[] args){
		File file = new File("D:/test.txt");
		try {
			FileWriter out = new FileWriter(file);
			String buy = "你好";
			out.write(buy);//参数必须为byte
			out.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			FileReader in = new FileReader(file);
			char buy[] = new char[10];
			in.read(buy);//参数为char类型
			System.out.println(new String(buy,0,buy.length));
			in.close();
		} catch (Exception e) {
			// TODO: handle exception
		}
		
	}
}


BufferedWrite  BufferedReader

public class test {
	public static void main(String[] args){
		File file = new File("D:/test.txt");
		String[] txt = {"你好","世界"};
		try {
			FileWriter out = new FileWriter(file);
			BufferedWriter bufw = new BufferedWriter(out);
			for(int k = 0;k<txt.length;k++){
				bufw.write(txt[k]);
				bufw.newLine();
			}
			
			bufw.close();
			out.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			FileReader in = new FileReader(file);
			BufferedReader bufr = new BufferedReader(in);
			String s = null;
			int i = 1;
			while((s = bufr.readLine()) != null){
				System.out.println("第" + i++ + "行  " + s);
			}
			bufr.close();
			in.close();
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
第1行  你好
第2行  世界

DataInputStream ....DataOutputStream

public class test {
	public static void main(String[] args){
		File file = new File("D:/test.txt");
		try {
		    FileOutputStream out = new FileOutputStream(file);
			DataOutputStream dos = new DataOutputStream(out);
		    
			dos.writeUTF("好的");
			dos.writeBytes("你好");
			dos.writeChars("世界");
			
			dos.close();
			out.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			FileInputStream in = new FileInputStream(file);
			DataInputStream dis = new DataInputStream(in);
			String s = dis.readUTF();
			System.out.println(s);
			dis.close();
			in.close();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}//read只能用utf来读取,因为他知道什么时候读取结束
//如果先write的不是UTF,那么也是无法成功读取的,因为不知道开始的位置 


Zip压缩与解压暂时没看懂,,也不想看,,等着更新吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值