java自学中的一些小问题(IO流)

IO流:

解决读文件后中文乱码问题(在inputstream中设置读取文件的格式)

FileInputStream fis = new FileInputStream(new File("E:/战网/Hearthstone/Strings/zhCN/CREDITS_2014.txt"));
InputStreamReader is = new InputStreamReader(fis, "utf-8");
BufferedReader br = new BufferedReader(is);
String s = null;
while((s = br.readLine())!= null){
System.out.println(s);
}



采用缓冲数组读取文件提高效率

BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
					String path));
			File descFile = new File("F://1.avi");
			FileOutputStream fos = new FileOutputStream(descFile);
			BufferedOutputStream bos = new BufferedOutputStream(fos);
			
			OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(descFile));
			BufferedWriter bw = new 
			long before = System.currentTimeMillis();
			
			byte[] b = new byte[1024*3];
			int hasRead = 0;
			while((hasRead = bis.read(b))!= -1){
				bos.write(b, 0, hasRead);
				bos.flush();
			}



复制一个文件夹

public static void copyFolder(File srcFile, File destFile) {
		File[] files = srcFile.listFiles();
		for (File f : files) {
			if (f.isDirectory()) {
				//File类的构造函数(destFile是f.getName()的上一级目录)
				File toFile = new File(destFile,f.getName()); 
				toFile.mkdirs();
				copyFolder(f, toFile);
			} else {
				File toFile = new File(destFile, f.getName());
				copyFile(f, toFile);
			}
		}
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值