java-为什么 函数不执行hfc.delete(path)函数;

问题描述

为什么 函数不执行hfc.delete(path)函数;
public static void updateLog(String code, String record, String fileName) {
    try {
        String content = code + " " + record
                + System.getProperty("line.separator");
        File file = new File(fileName);
        // file.mkdir();

        // if file doesn't exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }
        FileWriter fw = new FileWriter(file, true);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(content);
        bw.close();

        System.out.println("Log File updated");

    } catch (IOException e) {
        e.printStackTrace();
    }

    List list = new ArrayList();
    try {
        BufferedReader bw = new BufferedReader(new FileReader(fileName));
        String line = null;
        try {
            while ((line = bw.readLine()) != null) {
                list.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    int max = list.size();// TXT lines
    if (max > 10) {
        one_key();
    }
}

public static void one_key() {
    // delete the first line
    String filePath = "C:\LOG";
    String fileName = "AddLog.txt";
    del(filePath, fileName);

    // delete file
    httpHandler hfc = new httpHandler();
    String path = "C:\LOG\AddLog.txt";
    hfc.deleteFile(path);

    // copy the file
    // File files = new File("C:\LOG\test\");
    // File file[] = files.listFiles();// 获得目录中的文件及子目录信息
    // int i = (int) (Math.random() * file.length);
    // fun(file, i);

}

public static void del(String filePath, String fileName) {

    RandomAccessFile readFile = null;
    try {
        readFile = new RandomAccessFile(filePath + "\" + fileName, "r");
        readFile.readLine();
        readFile.readLine();
        readFile.readLine();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
    }
    RandomAccessFile writeFile = null;
    try {
        writeFile = new RandomAccessFile(filePath + "\test\" + fileName,
                "rw");
        String tempLine = null;
        while ((tempLine = readFile.readLine()) != null) {
            writeFile.writeBytes(tempLine);
            writeFile.writeBytes("rn");
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        readFile.close();
        writeFile.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public boolean deleteFile(String sPath) {
    boolean flag = false;
    File file = new File(sPath);
    // 路径为文件且不为空则进行删除
    if (file.isFile() && file.exists()) {
        file.delete();
        flag = true;
    }
    return flag;
}

public static void fun(File file[], int i) {
    if (file[i].exists()) {// 如果文件存在
        String name = file[i].getName();// 获取文件名
        if (file[i].isFile() && name.endsWith(".txt")) { // 如果是文件并且后缀名为.txt
            File dest = new File("c:\LOG\" + file[i].getName());
            file[i].renameTo(dest);
        } else {
            int j = (int) (Math.random() * file.length);
            fun(file, j);
        }
    } else {
        int j = (int) (Math.random() * file.length);
        fun(file, j);
    }
}
时间: 2024-08-01 18:36:33

java-为什么 函数不执行hfc.delete(path)函数;的相关文章

js函数 执行方式-javascript函数的执行方式?

问题描述 javascript函数的执行方式? javascript函数有哪些执行方式,有高手帮忙总结一下吗? 解决方案 不知道你说的方式按照什么分类,和别的编程语言类似,js的函数从调用方式上分为普通函数和回调函数,从定义方式看,分为命名函数和匿名函数,从调用者来说,分为递归函数和非递归函数. 解决方案二: 匿名(function(i){alert(i)})(11)显示申明的function func(i){alert(i)}func(1)变量式var func=function(i){ale

Windows Service中调用dll 回调函数不执行(在线等)

问题描述 WindowsService中调用dll回调函数不执行,非回调函数正常:部分代码publicdelegatevoidGESCALLBACK(stringExtNum,intstatus);[DllImport("ExtStatusShow.dll")]publicstaticexternintRegGetExtStatusCBEvent(GESCALLBACKFunc);...publicvoid_UpdateExtStatus(stringExtNum,intstatus)

java中为什么只进行一个初始化就会执行类中的函数

问题描述 java中为什么只进行一个初始化就会执行类中的函数 import java.awt.*;import javax.swing.*;import java.awt.event.*;public class E2 extends Frame{ class WindowCloser extends WindowAdapter { public void windowClosing(WindowEvent we) {System.exit(0); } } E2() { super(""

java quartz2 2 1使用-quartz 2.2.1 为什么不会执行myjob中的函数

问题描述 quartz 2.2.1 为什么不会执行myjob中的函数 代码如下: myjob拓展了job接口,可是程序执行的时候没有执行myjob中的print public class QuartzTest { public void run() throws Exception { // 调度工厂 SchedulerFactory sf = new StdSchedulerFactory(); // 从工厂中,获取一个任务调度实体 Scheduler sched = sf.getSchedu

speed-js运动的一个问题,为什么第一个函数不执行

问题描述 js运动的一个问题,为什么第一个函数不执行 #box{width: 100px;height: 100px;background: red;position: absolute;left: 0;top: 0;} js====== function act(obj, attr, target, fn){ clearInterval(obj.timer); obj.timer = setInterval(function(){ var cur = parseInt(css(obj, att

class-[java]关于main函数的执行先后顺序

问题描述 [java]关于main函数的执行先后顺序 在这个文件在执行的时候先执行那个呢?,如果把InvolveMain类里的方法写成注释后面的又先执行哪个呢?求详细解释一下,谢谢谢谢. package exercise5;//整个文件的类名是E20//创建一个使用可变参数列表而不是普通的main()语法的main().//打印所产生的args数组的所有元素,并用各种不同数量的命令行参数来测试它class InvolveMain{ static void main(String...args){

为什么执行output()函数时会有乱码,但是把texteditor类去掉就好了?

问题描述 为什么执行output()函数时会有乱码,但是把texteditor类去掉就好了? #include#include#includeusing namespace std;struct Node{ char str[20]; Node *next;}node;class LinkList{public: Node *head*tail;public: LinkList(){}; ~LinkList(){}; void Input() { int tag=0; Node *p*q; he

java中如何后台执行excel的保存功能?

问题描述 java项目中,我通过jxl的方式实现了excel的生成操作.但发现生成的xls格式的文件,并非是真正的MicrosoftOfficeExcel工作簿(.xls),其文件格式貌似是西欧编码的.直接用excel程序打开确正常!!这样以来就悲剧了~~我用其他在线预览插件就打不开这个excel了,比如大家熟悉的dsoframer.头疼了两天了,换成poi的方式生成xls,结果发现也是不行!不管是jxl还是poi,只要执行了write那个函数,文件流关闭后,生成的xls文件编码就有问题,用ex

【IOS-COCOS2D-X 游戏开发之十三】详细讲解在XCODE中利用预编译并通过JNI调用ANDROID的JAVA层代码(COCOS2DX里访问调用ANDROID函数)!

本站文章均为 李华明Himi 原创,转载务必在明显处注明: 转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/android-game/725.html 很多看过之前Himi的[iOS-cocos2d-X 游戏开发之七]整合Cocos2dX的Android项目到Xcode项目中,Xcode编写&编译代码,Android导入打包运行即可! 博文的童鞋都在问我如何在Xcode中能调用Java的函数,比如在Android端需要加入广告.支付.等第三方平台或者