开发者

Random deleting of text file on java learner training

So I'm working on a project where we created a supervised learner in Java. It uses a weight .txt file with about 15 lines (one number per line) that gets opened and closed twice per run. Opening and closing happens directly before and directly after reading/writing.

Because of the way the code is structured (not our decision), I cannot run our training code in a loop. So I setup a batch script that simply iterates over a loop, during each iteration running our code (and thus updating our file), waiting for a few seconds, and then repeating.

The problem is that every few hundred runs or so randomly, all the contents of our file gets deleted. The file still exists, but all the content is clear. Sometimes it'll happen on the 100th run, sometimes it'll happen on the 200th, sometimes on the 3rd.

Assuming it's not our code that is the problem, what could possibly cause this? Or possible fix?

Specs:

Windows 7

Making 'j开发者_JAVA技巧ava' calls to execute the .class file from a .bat batch file

modifies a .txt file in the same directory

Any help is greatly appreciated.


The fact that it happens so sporadically and finishes without complaining makes me think it's not the java.

I don't think you've ruled out your code as the source of the problem. As a counter-example, this Java program fails "sporadically" and "finishes without complaining" about one time in three. It's the essence of a swallowed exception. I'm going with the odds here: it's probably your code.

public class SilentSpring {
    /** Expected output: args[0] 0 */
    public static void main(String[] args) {
        try {
            long i = System.currentTimeMillis() % 3;
            System.out.print(args[0] + " ");
            System.out.println(0 / i);
        } catch (Exception e) {}
    }
}

Shell script:

for ((i = 1; i <= 32; i++)); do java -cp build/classes SilentSpring $i ; done

Console:

1 0
2 3 0
4 5 6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 14 15 0
16 0
17 18 0
19 0
20 0
21 22 0
23 24 0
25 26 0
27 0
28 0
29 0
30 31 0
32 0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜