I have a process in which very sporadically I’m creating files which for reasons that I can’t yet figure out I get a “java.io.FileNotFoundException: File is not a normal file.” exception even though the file appears (in the file manager and text editor) to be entirely healthy. So, I’m trying to recreate this error and see how I can deal with it but to do that I need to manually create a file that would raise this exception, and I have no clue what I could manually do to a file to have it suddenly become “broken” in this way.
I realize that whatever I will do to the file is not the same thing that is wrong with the files that are throwing my exception, but for the purpose of writing testable code to verify that my safeguarding code works, that won’t matter… I just need a broken file. I guess I could just throw the exception manually in some random cycle, but I was hoping I could get this to be more “realistic”.
All help appreciated.
If you want to corrupt an existing file just write a function that opens the file and scrambles the bytes. You can also do this with a hex editor. If you want to generate garbage files you can just create a new file and write a random.nextBytes() in to it.