How to read/write in .jar

Hello,I am a complete newbie in Java programing :)I want to know what's the simplest way to transfer the text from the field(on website) into example.jar and how to retrive the information.Thank you :)
[230 byte] By [alexa-lola] at [2007-11-27 3:34:57]
# 1
Read/ write in .jar?what are u trying to achieve?can u be more specific?
Bhannata at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 2

I want to achive...

On a website there is a field. In that field you can write words, numbers, whatever... now I want to make a script which enables me to write that piece of information into .jar file.

I want to be able to write pieces of information from the field on my website into the .jar file. File would be located on my server.

You know what I mean?

PS

I found a great way to extract Java resources from JAR and zip archives.

Now the problem is how to insert them.

alexa-lola at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 3
You can read from a .jar, but can not write into one.
abillconsla at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 4
> You can read from a .jar, but can not write into one.Well, you could write to a jar file using JarOutputStream: http://java.sun.com/javase/6/docs/api/java/util/jar/JarOutputStream.html
DrLaszloJamfa at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 5
Can I then somehow see the text which is stored in file.jar.For example...file.jar->there is "abcd" in file.jarcan I now see that text on the screen, in my browser?
alexa-lola at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 6
You can read from a jar, yes.
abillconsla at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 7
Here is the Sun tutorial on JAR files: http://java.sun.com/docs/books/tutorial/deployment/jar/index.html
DrLaszloJamfa at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 8

> > You can read from a .jar, but can not write into

> one.

>

> Well, you could write to a jar file using

> JarOutputStream:

> http://java.sun.com/javase/6/docs/api/java/util/jar/Ja

> rOutputStream.html

HuH? - " ... is used to write the contents of a JAR file to any output stream ... "

abillconsla at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 9

To read from a file - say a text file - that is located within the jarfile that your class file is in, you can code the following:

URL url = this.getClass().getResource("my_text_file.txt");

BufferedReader br = new BufferedReader(

new InputStreamReader( url.openStream() ) );

~Bill

Message was edited by:

abillconsl

abillconsla at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 10
thans for the manual :)Can I engage(start) .jar app simply by couble clicking on it? or must I insert the app into html code to be able to see it in action?
alexa-lola at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 11

> thans for the manual :)

> Can I engage(start) .jar app simply by couble

> clicking on it?

> or must I insert the app into html code to be able to

> see it in action?

If by 'app' you mean Applet or JApplet, then yes you need HTML. If by 'app' you mean Application, than no, you do not want HTML code, and you can start your jarfile by double clicking it. In the later case you need a manifest file with a main-class specified. The tutorial will spell this out.

abillconsla at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 12
thanks :)so .jar behaves like .html?Can I also add icon?
alexa-lola at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 13
> HuH? - " ... is used to write the contents of a JAR file to any output stream ... "Yes, that API comment is either misleading for a bit circular.
DrLaszloJamfa at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 14
> so .jar behaves like .html?Um, this thread is getting a bit wonky. A .jar file is basically a zip file with a "table of contents" called its manifest. Do you know what a zip file is? Would you ever say it "behaves" like a html file?
DrLaszloJamfa at 2007-7-12 8:38:06 > top of Java-index,Java Essentials,New To Java...
# 15

Jap, I know what zip is :)

So you get a list of files if you double click it?

Is there any way of seeing the actual content of. jar file?

Can I include some line of code into jar that it does not behave like zip file but like self extracting file which starts bebo.html and reads the images from the jar file when clicked?

alexa-lola at 2007-7-21 20:50:01 > top of Java-index,Java Essentials,New To Java...
# 16

> > HuH? - " ... is used to write the contents of a JAR

> file to any output stream ... "

>

> Yes, that API comment is either misleading for a bit

> circular.

But I don't think the OP wants to write a new jarfile entry, but modify an existing entry ... although I might be wrong since the request seems a bit vague.

abillconsla at 2007-7-21 20:50:01 > top of Java-index,Java Essentials,New To Java...
# 17

> Jap, I know what zip is :)

> So you get a list of files if you double click it?

> Is there any way of seeing the actual content of. jar

> file?

> Can I include some line of code into jar that it

> does not behave like zip file but like self

> extracting file which starts bebo.html and reads the

> images from the jar file when clicked?

First it was DrJam ... now Jap?! ;oP ... WoW ... anyway, you can get a list of the contents of a jarfile in a number of ways. The easiest manual way is to drag and drop onto WinZip if you have it. Otherwise run the jar command at the command prompt - you will see an optional parameter '-t' that will give you the table of contents.

I doubt we know what bebo.html is, but if what you want is zip file behavior, why not just use a zip file?

otherwise I am confused with what you really want to do.

abillconsla at 2007-7-21 20:50:01 > top of Java-index,Java Essentials,New To Java...
# 18

sit down and read :)

There is a file index.html. On that site there are 3 images 1, 2, 3.jpg.

I was wondering if there is any way of I could transform the site index.html and images into single .jar file which would show the content of the site(with images) in browser when clicked.

so from 4 files into 1 .jar files which shows the website when clicked.

This is my objective :)

alexa-lola at 2007-7-21 20:50:01 > top of Java-index,Java Essentials,New To Java...
# 19
No you can't put the html into the jarfile with the class file/s and expect it to work. You can put html into a jarfile and use that html to be displayed in something like a JTextPane, but you can't expect to run a zipfile from the internet.
abillconsla at 2007-7-21 20:50:01 > top of Java-index,Java Essentials,New To Java...
# 20
OK :)Can one make jar to self-exctract itself?
alexa-lola at 2007-7-21 20:50:01 > top of Java-index,Java Essentials,New To Java...
# 21
> OK :)> Can one make jar to self-exctract itself?No. A zip file can be configured to be self-extracting. However, it's not just a file with a .zip extension, then.
ChuckBinga at 2007-7-21 20:50:01 > top of Java-index,Java Essentials,New To Java...
# 22
> so from 4 files into 1 .jar files which shows the> website when clicked.> > This is my objective :)And what is the point of this objective?
DrClapa at 2007-7-21 20:50:01 > top of Java-index,Java Essentials,New To Java...