• Post Reply Bookmark Topic Watch Topic
  • New Topic

desktop.print do not function when i try to print html file  RSS feed

 
alper kopuz
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I try to print a html file by using Desktop.print I come across with the following error. I have seen similar and sometimes same questions in the forum but unfortunately noone provided an answer for the problem.Any help is appreciated.It is fine when you try to print a txt file but when it comes to print a html file, it gives following error.

Regards

Alper

      Desktop desktop = Desktop.getDesktop();
      desktop.print("test.html");


"Error message: A device attached to the system is not functioning."
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume by the Desktop class you are referring to java.awt.Desktop ?
It has a method:  void print(File file)

The method takes a file whereas the code you have provided shows you passing "test.html" - which is a string representing the name of the file.

I would expect the code to be more like:


Where is the file "test.html" residing on your disk?  You may need to modify the "pathToFile" to find it correctly.

Is there more to the error message you have provided?  Maybe an exception stack trace?  Posting that would help figure out what is going wrong in more detail.

 
alper kopuz
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Stefan

Yes, I meant java.awt.desktop .

You are right but I did not give the full link of the test.html.Normally I write it like that, and it still gives same error. It means the error is not related with the path of the file but it is related with the type of the file called "html". It is able to print file when it is "txt"  but gives "a devices attached to the system is not functioning " error when type of the file is html.

Regards
Alper


Desktop desktop = Desktop.getDesktop();
FileSystem fileSystem   = FileSystem.getDefault();
File file  = new File("C:\test.html")
desktop.print(file);
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there more to the error message you have provided?  Maybe an exception stack trace?  Posting that would help figure out what is going wrong in more detail.


If it works with "txt" but not "html" I would hazard a guess that your operation system doesn't know what to do with html files. 
The error message should probably be:  "There is no application associated with the given file name extension." (similar to https://bugs.openjdk.java.net/browse/JDK-8064934)

If you double click the html file what opens up?
Does it have a "print" operation on its context menu when you "right click" the html file?
 
alper kopuz
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Stefan

Thanks for your help.

Exactly it is same with "There is no application associated with the given file name extension". When I right click the html file, it does not have print operation on its context menu but it shows a print operation when it is txt file.

What I need to do to see print operation on its context menu when it comes to html file ? I can resolve it by showing default print operation to html files ?

Best Regards
Alper
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!