Java 课下练习题 T4

1. 对指定的图片(>2M)进行复制,将其复制到另外一个文件夹下,要求使用InputStream,OutputStream或它们的子类来实现。

2. 对指定的文本文件进行从头到尾的遍历,并将遍历的内容写入到另外一个文件里。

3. 把键盘输入的内容写入到文本文件中,按以下格式



4、 设计一个类读取用户输入的文本行并对文本行进行编码,然后输出编码的文本行,编码要求:将字母表中的每个字母用其后第 13 个位置的字母代替.

5、 将一个文件的内容装换为大写,显示出来,并把内容复制到文件中去。

6、 书写一个以.properties命名的文件这个文件的特点是以key=value的形式书写文件内容例如

key1=value1

key2=value2

key3=value3

..

然后当用户输入指定的key值时能够准确的把其对应的value值取出。

7、 使用学习的IO知识构建一个基于控制台的应用程序,要求具有系统欢迎菜单功能,并且可以循环选择菜单,在选中相应的项目的时候进入二级菜单进行执行,执行完毕可以返回上一级菜单,用户可以根据需要退出系统

package zuoye4;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class T1 {

	 public static void main(String[] args) throws IOException {
	        
	        demo1();	       
	 
	    }
	public static void demo1() throws FileNotFoundException, IOException {
		FileInputStream fis = new FileInputStream("E:\\x.jpg");
		FileOutputStream fos = new FileOutputStream("d:\\01.jpg");
		int len = 0;
		byte[] buf = new byte[4096];
		while ((len = fis.read(buf)) != -1) {
			fos.write(buf, 0, len);
		}
		fis.close();
		fos.close();
	}
	
}

package zuoye4;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class T2 {
	public static void main(String[] args) {

	FileReader fr = null;
	char ch[] = new char[100];
	try {
		fr = new FileReader("E:/a.txt");
		//char ch[] = new char[100];
		int len = fr.read(ch);
		for (int i = 0; i < len; i++) {
			System.out.println(ch[i]);
		}
		
		String ss = new String(ch,0,len);
		System.out.println(ss);
		
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	finally{
		try {
			fr.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		fr = null;
	}
	
	FileWriter fw = null;
	String strStringType="my string";
	strStringType= String.valueOf(ch);
	
	
	try {
		fw = new FileWriter("E:/at2.txt");
		fw.write(strStringType);
		fw.flush();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	finally{
		try {
			fw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		fw = null;
	}
	
	
}
}

package zuoye4;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class T3 {
	private static Scanner sc;  
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		String ch;
		ch =sc.nextLine();
		FileWriter fw = null;		
		try {
			fw = new FileWriter(new File("E:/aa3.txt"),true);
			fw.write(ch+"\r\n");
			fw.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{
			try {
				fw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			fw = null;
		}
	}
}

package zuoye4;

import java.util.Scanner;

public class T4 {
	public static void main(String[] args) {
        String lower="abcdefghijklmnopqrstuvwxyz";
        String upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        @SuppressWarnings("resource")
		Scanner sc= new Scanner(System.in );
        String text=sc.nextLine();
        StringBuilder sb= new StringBuilder();
        final int offset=13;
        for (char A:text.toCharArray()) {
            if (Character.isLowerCase(A)) {
                sb.append(lower.charAt((lower.indexOf(A)+offset)%lower.length()));
            } else {
                sb.append(upper.charAt((upper.indexOf(A)+offset)%upper.length()));
            } 
        } 
        System.out.println(sb.toString());
}
	      
}

package zuoye4;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;



public class T5 {

	public static void main(String[] args) {
		
				
		FileReader fr = null;
		String uppercase = new String();
		char ch[] = new char[100];
		try {
			fr = new FileReader("E:/a5.txt");			
			int len = fr.read(ch);
			for (int i = 0; i < len; i++) {
				System.out.println(ch[i]);
			}
			
			String ss = new String(ch,0,len);
			System.out.println(ss);
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{
			try {
				fr.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			fr = null;
		}
		FileWriter fw = null;
		String strStringType="my string";
		strStringType= String.valueOf(ch);		
		uppercase = strStringType.toUpperCase();
		
		try {
			fw = new FileWriter(new File("E:/a5.txt"),true);
			//fw = new FileWriter("E:/at2.txt");
			fw.write(uppercase);
			fw.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{
			try {
				fw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			fw = null;
		}
		System.out.println(uppercase); 
		
	}
}

package zuoye4;


import java.io 

.FileInputStream;
import java.io 

.IOException;
import java.io 

.InputStream;
import java.util.Properties;
import java.util.Scanner;

public class T6 {
	private static Scanner sc;  
	 public static void main(String args[]) throws IOException {
		 
		 test4f();
 }
 public static void test4f() throws IOException {
	 	sc = new Scanner(System.in);
		String ch;
		ch =sc.nextLine();
         InputStream is = new FileInputStream("E:\\a6.properties");
         Properties prop = new Properties();
         prop.load(is);
         System.out.println(prop.getProperty(ch)); 
 }
}

package zuoye4;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class T7 {

	public static void main(String[] args) {
		int num ;
		String str ;
		BufferedReader brd=new BufferedReader(new InputStreamReader(System.in)) ;
		while(true)
		{
			
			System.out.println("欢迎来到欢迎系统") ;
			System.out.println("----------------------") ;
			System.out.println("进入登录系统请输入1") ;
			System.out.println("进入注册系统请输入2") ;
			System.out.println("退出系统请输入0") ;
			System.out.println("请输入数字:") ;
			try
			{
				str=brd.readLine() ;
				num=Integer.parseInt(str) ;				
				if(num==1)
				{
					fun1();
				}
				else if(num==2){
					fun2();
				}
				else if(num==0){
					System.out.println("正在退出") ;
					break;
				}
				else System.out.println("对不起,只能输入0、1、2,请重新输入。") ;
					
			}
			catch(Exception e)
			{
				System.out.println("对不起,只能输入整数,请重新输入。") ;
			}
		}	
	}

		public static void fun1(){
			System.out.println("欢迎来到登录系统") ;
			System.out.println("返回上一步请输入0") ;
			System.out.println("请输入数字:") ;
			BufferedReader brd1=new BufferedReader(new InputStreamReader(System.in)) ;
			int num1;
			while(true){
			try
			{
				
				String str=brd1.readLine() ;
				num1=Integer.parseInt(str) ;				
				if(num1==0)
				{
					break;
				}
								
			}
			catch(Exception e)
			{
				System.out.println("对不起,只能输入整数,请重新输入。") ;
			}
			}
		};
		public static void fun2(){
			System.out.println("欢迎来到注册系统") ;
			System.out.println("返回上一步请输入0") ;
			System.out.println("请输入数字:") ;
			BufferedReader brd1=new BufferedReader(new InputStreamReader(System.in)) ;
			int num2;
			while(true){
			try
			{
				
				String str=brd1.readLine() ;
				num2=Integer.parseInt(str) ;				
				if(num2==0)
				{
					break;
				}
								
			}
			catch(Exception e)
			{
				System.out.println("对不起,只能输入整数,请重新输入。") ;
			}
			}
			
		};				
}	
			

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值