Question

My machine crashed while I was developing on IntelliJ IDEA and when I loaded the project again, the main.java file was empty. When I opened the file in notepad++, there were only "NUL NUL NUL NUL NUL" characters. Like this: " "

Was it helpful?

Solution

It may be a stretch but... There may be .class files which IntelliJ compiled from your .java source code.

For example:

{main IDEA project DIR}/untitled/out/production/untitled/Main.class

Where "untitled" would be your project name (this is an example with a directory structure under Linux: you'll probably need to adapt for Windows).

If you manage to find that (those) file(s) you then may be able to use a Java decompiler to get you source code back from that (those) .class file(s). Note that a single .java file may give more than one .java file (for example if you have inner classes inside your main.java).

I wouldn't bother if it's small (I'd simply rewrite it) but if you had a big main.java file (which btw is never a good idea), then it may be worth it.

For the next time, as has already been suggested: look into a (D)VCS and use backups :)

OTHER TIPS

You might be able to recover lost files using a file recovery tool, but the chances are that the file is lost forever. (This is why it is a good idea to take regular backups, and put a copy of your code into a version control repository on a separate machine ...)

There are lots of file recovery tools for Windows, and recommending one is off-topic for SO.

I suppose that decompiling a ".class" file is another option if you are totally desperate. But you won't get any of your comments back, or names of local variables, etc. And if your code is complicated, the decompiled code could be different ... and not necessarily correct and compilable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top