开发者

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

For my program I have 2 questions:

  1. The program I am creating will act like MS Office. How do I associate Word, Excel, and PowerPoint files with my program?
  2. My program lets the user use a lot of code associated with Java (JPanel). Is there any other format to save a file other than a *.java file (Such as *.A2W Alice files)? Also I can't understand how Alice reads and saves 开发者_运维问答*.A2W!

Can somebody help me?


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.


How do I associate Word, Excel, and PowerPoint files with my program?

Java Web Start can request file associations for file types.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜