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();
}
}
}