java 刷新文件夹 代码_UpdateFile.java(更新指定文件夹的文件)作者:阿飞

/*

* 创建日期 2004-12-14

*

* TODO 要更改此生成的文件的模板,请转至

* 窗口 - 首选项 - Java - 代码样式 - 代码模板

*/

package net.selfcafe;

import java.io.*;

/**

* @author Administrator

*

* TODO 要更改此生成的类型注释的模板,请转至

* 窗口 - 首选项 - Java - 代码样式 - 代码模板

*/

public class  UpdateFile

{

//遍历整个文件加

public  static void SearchAllDec(String path) {

int size;

String subpath="";

File newfile = new File(path);

if (newfile.isDirectory()) {

//System.out.println(newfile.getName());

String filelist[] = newfile.list();

size = filelist.length;

for (int i = 0; i < size; i++) {

subpath = path + "/" + filelist[i];

SearchAllDec(subpath);

}

} else if (newfile.isFile()) {

//得到文件路径

String strFilePath = newfile.getAbsolutePath();

String strFileContent = "";

String strFileName = newfile.getName();

String strFileExt = strFileName.substring( strFileName.length()-3,strFileName.length() );

//如果是asp文件,得到文件中的内容

strFileContent = getStrFromFile(strFilePath);

if (strFileExt.equals("asp")){

MakeNewFile(path,strFileName,strFileContent);

}

} else {

System.out.println("no such file or directory");

}

}

/*

*

* 得到文件的内容

* */

public static String  getStrFromFile(String strFileNameAndPath)

{

BufferedReader br= null;

StringBuffer s=new StringBuffer();

String line = "";

int iLineCount = 0;

int iSum = 0;

try{

br = new BufferedReader(new FileReader(strFileNameAndPath));

iLineCount = 0;

while( (line=br.readLine())!=null)

{

//处理页面如果,如果包含框架的去掉

iLineCount ++;

String strResult;   //临时字符串

//boolean iChangeFlag = false;//保证成对出现

strResult = "/" frameborder=/"0/" scrolling=/"no/" width=/"778/" height=/"145/">";

if (line.indexOf(strResult)>-1)

{

System.out.println("Line:"+ iLineCount);

System.out.println(line);

iSum++;

line = "

/n";

}

strResult = "

";

if (line.indexOf(strResult)>-1)

{

System.out.println("Line:"+ iLineCount);

System.out.println(line);

line = "/n";

}

s.append(line);

s.append("/n");

}

System.out.print(iSum+ "");

}catch(Exception e){

}

String result = new String(s);      result = result.trim();          return result;    } /*  *  ==生成新的页面  *   * */    public static boolean MakeNewFile(String strFilePath ,String strFileName,String newsContent){  File path=null;  File d=null;  //System.out.println(strNewsPath);  try  {       path=new File(strFilePath);    //System.out.println("1");   if(!path.exists())    path.mkdir();        System.out.println(" 文件名称:"+strFilePath);    //System.out.println(strFileName);    String  tempStr = strFilePath.trim();      //写入html文件      FileWriter fw;     try     {                 fw=new FileWriter(tempStr);//建立FileWriter对象,并实例化fw        //将字符串写入文件           fw.write(newsContent);           fw.close();       }       catch(Exception e)          {         e.printStackTrace();             }      }catch(Exception e){   System.err.println(e);   e.printStackTrace();   return false;  }finally{   path=null;   d=null;  }    return true; }  public static void main(String[] args)  {  SearchAllDec("h:/test");   }}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值