昨天的代码

package com.swpu.khl.io;

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

public class FileTest 
{
	public static void main(String[] args) 
	{
		try 
		{
			FileInputStream fis=new FileInputStream("G:\\test1.txt");
			int ch=0;
			byte [] len=new byte[1024];
			while((ch=fis.read(len))!=-1)
			{
				System.out.print(new String(len,0,ch));
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		
		/*try
		{
			FileReader fr=new FileReader("G:\\test1.txt");
			int ch=0;
			char [] buf=new char[1024];
			while((ch=fr.read(buf))!=-1)
			{
				System.out.print(new String(buf,0,ch)+"**********");
			}
		}
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		}
		catch (IOException e) 
		{
			e.printStackTrace();
		}*/
		
		try
		{
			//                                           如果文件已存在且有值,就不覆盖之前的文件,而是添加到末尾
			FileWriter fw=new FileWriter("g:\\test1.txt",true);
			fw.write("\r\ntest2");
			fw.flush();
		}
		catch (IOException e) 
		{
			e.printStackTrace();
		}
		
		/*try 
		{
			FileOutputStream fos=new FileOutputStream("g:\\test2.txt");
			fos.write(65);
		}
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}*/
		
		/*try 
		{
			FileInputStream fis=new FileInputStream("G:\\test1.txt");
			FileOutputStream fos=new FileOutputStream("G:\\test2.txt",true);
			
			//byte[] ch=new byte[1024];
			int len=0;
			while((len=fis.read())!=-1)
			{
				fos.write(len);
			}
		}
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}*/
		
		/*try
		{
			FileReader fr=new FileReader("g:\\test1.txt");
			char [] buf=new char[1024];
			int len=0;
			while((len=fr.read(buf))!=-1)
			{
				System.out.print(new String(buf,0,len));
			}
		}
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}*/
	}
}
package com.swpu.khl.io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class BufferTest 
{
	public static void main(String[] args) 
	{
		/*try
		{
			FileWriter fr=new FileWriter("g:\\bufTest.txt");
			BufferedWriter bw=new BufferedWriter(fr);
			for(int x=0;x<5;x++)
			{
				bw.write("sdfds"+x);
				bw.newLine();
				bw.flush();
			}
		}
		catch (IOException e) 
		{
			e.printStackTrace();
		}*/
		
		/*try
		{
			FileReader fr=new FileReader("g:\\bufTest.txt");
			BufferedReader br=new BufferedReader(fr);
			String line=null;
			while((line=br.readLine())!=null)
			{
				System.out.println(line);
			}
		} 
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}*/
		
		/*try
		{
			BufferedReader br=new BufferedReader(new FileReader("g:\\bufTest.txt"));
			BufferedWriter bw=new BufferedWriter(new FileWriter("g:\\copyBuf.txt"));
			String line=null;
			while((line=br.readLine())!=null)
			{
				bw.write(line);
				bw.newLine();
				bw.flush();
			}
		}
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}*/
		
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
		
		String line=null;
		try {
			while((line=br.readLine())!=null)
			{
				if(line=="over")
					break;
				bw.write(line.toUpperCase());
				bw.newLine();
				bw.flush();
				
			}
		}
		catch (IOException e) 
		{
			e.printStackTrace();
		}

	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值