Starting HTML/CSS/Javascript file from Java - java

I have written an Java code that process some data and stores it in .JSON format.
I also have HTML/CSS/Javascript file, that reads that data, and shows it in much nicer way.
So my question is, is it possible to combine Java and HTML code(in one file .jar) so that, for example on a click of a mouse Java opens HTML file in Default browser?
Thanks

Write out the html file to the filesystem (e.g. a temporary directory How to create a temporary directory/folder in Java?) and then open it using the default program: How to open a file with the default associated program

Related

Two applications need to export and import a single file which needs to include data and images, best file type?

I'm making two Java applications one to collect data, another to use it. The one collecting will be importing a file from the other which will include data and images and will be decrypted.
I'm unsure what filetype to use. So far all of the data is in XML and works great but I need the images and was hoping not to have to rely on giving all the images in a folder with a path reference.
Ideas?
well, I think that the best way is to create your own format (.myformat or .data). This file will be in fact a Zip file that contains your XML file and images.
There is no perfect example writen in java as far as I know. However, here are some examples :
Not in java
The best example is, as #Bolo said, the odt format. Indeed, OpenOffice writes the doc in an xml file, and the images too. All that is wrapped in an odt file.
The .exe file is an other example. The C files and the resources are put in a single file. try to open it with 7-zip, you'll see.
The Skyrim plugins are .esp file that contain the dds, the scripts, the niffs (textures)...
In java
The minecraft texture packs are a zip file that contains a .mcmeta file (the infos) and the textures (.png)
Jar files are like exe.
If both programs are in java you could also go with serialization, which is basically saving an object as a file (suffix will be .ser I think) and then being able to retrieve it. You should google it, even if it won't help right now it is quite good to know about it.
I'd suggest using JSON. Gson is a decent library.
You can embed images as byte arrays.
Save the serialized string in a file with a preferred extension, read it from the second application, de-serialize, and reconstruct images.
You can convert binary image data to text with Base64 encoding and this way you can embed your images in XML. [1]: http://en.wikipedia.org/wiki/Base64

Update data documents for JWS deployed app

I have a swing application that uses many data files, these data files will change time to time. How can I load these data files on client's machine? Is there any way to create a folder like structure and run a batch file or so? Any help is appreciated.
There are several ways to do this:
Assume you want to ship your application with the datafiles, you may embed them as a zip/jar in your application-jar-file.
Extract the embedded zip to a temporary local file and use ZipFileSystemProvider to extract the content to some place on the disc.
Here is an example how to extract some content from zip/jar-file embedded in a .jar-file downloaded by JWS.
Same as 1, but skip the zip stuff and instead provide a list of all the resources you want to extract
One other way is to create the files pragmatically using either java.nio.file (java 7+) or java.io.File

How can print multiple pdf files by reading from source and send to printer

I already tested window.print() command for this purpose but it is not fulfill my requirement.
I also used print content of iframe in which source is pdf file but it is only work in chrome not in other browser.
I want to print pdf files automatically using code instead of open file and print it.
For example there are two files such as 1.pdf and 2.pdf in any directory and source is given then how can print both files using either javascript or php or both.
I already tested window.print() command for this purpose but it is not fulfill my requirement.
My required as image as:
Million thanks in advance.
This is not possible since most browsers, unlike google chrome (where it works) don't have a built in pdf viewer.
The printing of a pdf document is up to the pdf reader, whether or not it is installed as a browser plugin, not the browser.
I fix this issue of merging multiple pdf or image or both by using imageMagick.
Using below command we can merge pdf and image as:
<?
$cmd = "test.pdf test.jpeg final.pdf";
exec("convert $cmd");
?>
After completed merging process, open final.pdf automatically using code then user can print it easily.
You can find more.

Using zip file without extracting in java

I'm facing a problem that, we have a .zip file that contains some text files. Now I'm using java to access that files. If it is not in the .zip file I can read and print on my console easily using FileInputStream.
But how to read a file from .zip file? I use J2SE only..
You should try a ZipInputStream. The interface is a little obtuse, but you can use getNextEntry() to iterate through the items in the .zip file.
As a side note, the Java class-loader does exactly this to load classes from .jar files without extracting them first.
Everything you need is in ZipFile: https://docs.oracle.com/javase/7/docs/api/java/util/zip/ZipFile.html. Google for examples on the web, and if you have specific problems then come back to SO for help.
(The link will eventually break; when it does simply websearch java zipfile.)

Embedded Applet Cannot Read File

I imagine this would be a very rudimentary problem, since I am not quite familiar with applet deployments: I was made to convert a Swing application into an applet and embed it to a webpage. This applet constructs its knowledge base by reading lines from a text file (in the same directory as the .class file), and when I launched it from the applet viewer it reads the file with no problem.
Upon embedding, however, it fails to read the file and the exception handling is triggered. Perhaps this is one of those security restrictions?
I use File, FileReader, and LineNumberReader to read this document.
Additional problem: this also happens with images, where the applet would not run at all. I temporarily got around this by placing said images within an HTML file, but it could be done much better.
Don't try to load it directly using a file - use Class.getResourceAsStream and InputStreamReader. In other words, load it as a resource rather than as a file.

Categories

Resources