Copying files from a Jar
Hi
I have been reading about InpuStream and JarInputStream and that sort of thing.
My situation is this. I have a client/server model. The client connects to the server opens up the browser. My applet starts and its at this point that i want to copy 2 files into their java_home/lib and java_home/bin(i have been able to get their java home directory, thats not an issue) directories. The applet downloads a signed jar file.
What would be the appropriate way for the applet to copy the 2 files contained within the JAR file?(I have access writing to their HDD). The first file is a *.properties and the second is a DLL.
Any suggestions are welcomed
Thank you
:)
[704 byte] By [
monk3ya] at [2007-11-27 8:30:38]

Ok so this is where i am in my code
I have been able to get the number of bytes in the Jar file and i have been able to write the files out to the right directories as my code will show below.
My problem is that there is 0 bytes in my new files
When i print out the file sizes it is correct, but for some reason when i write to the new files, its 0
The files i'm trying to copy are win32com.dll and javax.comm.properties
MY code is still very rough, i will clean it up when i have it working so please don't say anything about the horribly state my code is in, thnx :)
InputStream is = getClass().getResourceAsStream("win32com.dll");
InputStream isProp = getClass().getResourceAsStream("javax.comm.properties");
JarInputStream in = null;
FileOutputStream out = null;
try {
System.err.println("Available: "+is.available());
System.err.println("Available Javax: "+isProp.available());
in = new JarInputStream(is);
out = new FileOutputStream(System.getProperty("java.home")+"/bin/win32com.dll");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
System.err.println("CLOSED IN");
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
try {
System.err.println("CLOSED Out");
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
The print outs AVAILABLE give me the right number of bytes so i know that its finding the files and so do the Closed print outs
So any ideas why its not writting the files with the data in them?
Thanx
:)
nvm i got it working....
The problem was that i wasn't using DataInputStream
Here is my code, again its not pretty but it works.(Clean it up yourself)
I read files from a jar file and write new files into their respective directories
InputStream is = getClass().getResourceAsStream("win32com.dll");
InputStream isProp = getClass().getResourceAsStream("javax.comm.properties");
DataInputStream in = null;
FileOutputStream out = null;
DataInputStream inProp = null;
FileOutputStream outProp = null;
try {
in = new DataInputStream(is);
out = new FileOutputStream(System.getProperty("java.home")+"/bin/win32com.dll");
inProp = new DataInputStream(isProp);
outProp = new FileOutputStream(System.getProperty("java.home")+"/lib/javax.comm.properties");
int c;
int b;
while ((c = in.read()) != -1) {
out.write(c);
}
while ((b = inProp.read()) != -1) {
outProp.write(b);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (inProp != null) {
try {
inProp.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (outProp != null) {
try {
outProp.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}