周一第15天未完

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/myloveprogrmming/article/details/82871081
package a;

import java.io.*;
import java.util.Scanner;
/*4.在控制台输入一句英语, 获得每个字母出现的次数,注:每个字符作为key,出现的次数作为value*/

public class TestA {

	static void f1()throws IOException //单个字写 
	{
		FileInputStream in=new FileInputStream("D:\\11.txt");
		FileOutputStream out=new FileOutputStream("D:\\12.txt");//如果该文件不存在则创建文件,如果存在会覆盖
		int i;
		while((i=in.read())!=-1) 
		{
			out.write(i);
		}
		out.close();//从上往下开,就从下往上关
		in.close();
	}
	
	static void f2()throws IOException//一次性写
	{
		FileInputStream in=new FileInputStream("D:\\11.txt");
		FileOutputStream out=new FileOutputStream("D:\\12.txt");
		byte[] b=new byte[in.available()];//一次性读到byte中
		in.read(b);
		out.write(b);
		out.close();//从上往下开,就从下往上关
		in.close();

	}
	static void f3()throws IOException //将文件内容输出到控制台
	{
		FileInputStream in=new FileInputStream("D:\\11.txt");
		Scanner sc=new Scanner(in);
		String str=null;
		while(sc.hasNext()) {
			str=sc.nextLine();
			System.out.println(str);
		}
		sc.close();
		in.close();
	}
	static void f4()//跳着读,一次读10个
	{
		FileInputStream in=new FileInputStream("D:\\11.txt");
		FileOutputStream out=new FileOutputStream("D:\\12.txt");
		byte[] b=new byte[in.available()];
		
	}
	public static void main(String[] args) throws IOException 
	{
		
	}
}

猜你喜欢

转载自blog.csdn.net/myloveprogrmming/article/details/82871081