读文件、修改文件
/**
* 读取txt文件
*/
public void readerTXT(){
List<String> emailList=new ArrayList<String>();
List<String> emailLocationList=new ArrayList<String>();
File file=new File("C:\\Documents and Settings\\Administrator\\桌面\\email2.txt");
try
{
BufferedReader input=new BufferedReader(new FileReader(file));
String text;
while((text=input.readLine())!=null)
//System.out.println(text);
emailList.add(text);
} catch(Exception ex) {}
if(emailList!=null){
for(int i=0;i<emailList.size();i++){
String emailStr=emailList.get(i);
if(emailStr!=null&&!"".equals(emailStr)){
String [] emailArray=emailStr.split(";");
for(int j=0;j<emailArray.length;j++){
if(emailArray[j]!=null&&!"".endsWith(emailArray[j])){
emailLocationList.add(emailArray[j]);
}
}
}
}
}
for(int i=0;i<emailLocationList.size();i++){
System.out.println(emailLocationList.get(i));
}
}
/**
* 写入文件
*/
public void writerFile(){
File file=new File("C:\\Documents and Settings\\Administrator\\桌面\\发送成功.txt");
try {
FileWriter fw = new FileWriter(file);
fw.write("wangwei <wangwei.0822>\r\n");
fw.write("wangwei <wangwei.0822>\r\n");
fw.flush();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 文件copy
*/
public void copyFile(){
File filei=new File("D:\\aaa.txt");
File fileo=new File("D:\\bbb.txt");
try {
FileInputStream in=new FileInputStream(filei);
FileOutputStream out=new FileOutputStream(fileo);
byte [] b=new byte[1024];
while((in.read(b)>-1)){
out.write(b);
}
in.close();
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}