import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class TestFile {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File f;
FileReader in;
FileWriter out;
f=new File("c:\\test.txt");
if(f.exists()){
f.delete();
}else{
try{
f.createNewFile();
in=new FileReader(f);
String str="好好学习,天天向上";
}catch(IOException e){
e.printStackTrace();
}
}
}
}
package Testio;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class Testio {
public static void main(String args[]){
File f;
FileReader in;
FileReader out;
f=new File("c:\\test.txt");
if(f.exists()){
f.delete();
}else{
try{
f.createNewFile();
in=new FileReader(f);
String str="haohaoxuexi";
}catch(IOException e){
e.printStackTrace();
}
}
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class TestFile {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File f;
f=new File("c:\\test.txt");
FileWriter out;
FileReader in;
try{
/*
String str="白日依山尽,黄河入海流\r\n欲穷千里目,更上一层楼。";
out=new FileWriter(f);
out.write(str);
out.close();
*/
in=new FileReader(f);
char cbuf[]=new char[(int)f.length()];
in.read(cbuf);
System.out.println(new String(cbuf).trim());
in.close();
}catch(FileNotFoundException e1){
e1.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
}