千峰JAVA第32天作业

在千峰第32天
“只有用汗水磨砺,天赋才会绽放出耀眼的光”
中国加油,武汉加油,千峰加油,我自己加油。
1、
ABC
2、
file=new File(“hello.txt”);
if(file.exist()){
System.out.println(file.getAbsolutePath());
}
10、
A:能将字符写入输出流,默认编码
B:可以换行,默认编码
C:可以改变编码方式
11、
Ⅰ字符流
Ⅱ字符流
Ⅲ字符流
Ⅳ字节流
Ⅴ字节流
12、
1:1357
2:1467
3:17
4:17
5:13
6:14
7:24679
8:14679
9:278
14、

public class TEST14 {
	public static void main(String[] args) throws IOException {
		InputStream is = new FileInputStream("test.txt");
		InputStreamReader isr = new InputStreamReader(is,"UTF-8");
		BufferedReader br = new BufferedReader(isr);
		OutputStream os = new FileOutputStream("test2.txt");
		OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
		PrintWriter pw = new PrintWriter(osw);
		while(true){
			String s = br.readLine();
			if(s == null){
				break;
			}
			pw.println(s);
		}
		pw.flush();
		br.close();
		pw.close();
	}
}

17、

import java.io.*;
import java.util.Scanner;
public class TEST17{
	public static void main(String[] args) throws IOException {
		InputStream is = new FileInputStream("worldcup.txt");
		InputStreamReader isr = new InputStreamReader(is,"UTF-8");
		BufferedReader br = new BufferedReader(isr);
		System.out.println("请输入一个年份:");
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		while(true){
			String s  = br.readLine();
			if(s.contains(str)){
				char[] chr = s.toCharArray();
				for(int i = s.indexOf("/") + 1 ; i < s.length(); i++){
					System.out.print(chr[i]);
				}	
			}else{
				System.out.println("没有举办世界杯");
			}
		}
	}
}

18、

public class TEST18 {
	public static void main(String[] args) throws IOException {
		Scanner sc= new Scanner(System.in);
		System.out.println("请输入文件名:");
		String s = sc.next();
		File file = new File(s);
		if(file.exists()){
			InputStream is = new FileInputStream(s);
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);
			OutputStream os = new FileOutputStream("copy_" + file.getName());
			OutputStreamWriter osw = new OutputStreamWriter(os);
			PrintWriter pw = new PrintWriter(osw);
			while(true){
				String s1 = br.readLine();
				if(s1 == null){
					break;
				}
				pw.println(s1);
			}
			pw.flush();
			br.close();
			pw.close();
		}else{
			System.out.println("该文件不存在");
		}
	}
}
发布了21 篇原创文章 · 获赞 0 · 访问量 1956

猜你喜欢

转载自blog.csdn.net/qq_40091389/article/details/104933028