[Solved] Associating file types with program and saving files with extensions other than .java


For the first, it depends on the operating system, which you have not specified. If it’s on Windows, there is a pair of Windows commands: assoc and ftype. Each type of file is given a “type name.” assoc associates an extension with a type, and ftype associates a type with a command to execute.

For example, on my workstation I’m using now, I have .jar associated with jarfile assoc .jar=jarfile and jarfile associated with “C:\Program Files\Java\jre6\bin\javaw.exe” -jar “%1” %* ftype jarfile="C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %*

Note: You need to be in the administrators group to do this.

For the second question (which probably should have been in a separate question), .java is not a file format. .java files are actually just plain text files. The code for most programming languages is like that, so it’s equivalent to a .txt file so you can read and write it in any editor you prefer. The file extension merely lets the java compiler know that the code is in fact java code even though it’s in a plain text format.

The java compiler, however, will not normally compile code that has an extension other than .java If I try, I get the error error: Class names, 'myFile.blah', are only accepted if annotation processing is explicitly requested This leads me to believe that there is a way to get it to compile anyway, possibly by providing it with some custom annotation processors? I’m not sure, I have never done anything like that. Still, if the code is Java code, you can just let it have a .java extension.

1

solved Associating file types with program and saving files with extensions other than .java