 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Québec Guest
|
Posted: Sun Nov 23, 2003 2:51 pm Post subject: printing to a txt file in a jar |
|
|
Hi,
For sure Ifind theese jar things are intricated.
pw = new PrintWriter ( new
FileWriter(MusicCatalog.class.getResourceAsStream("catalog.txt") , true));
JPD
|
|
| Back to top |
|
 |
Québec Guest
|
Posted: Mon Nov 24, 2003 1:09 pm Post subject: jarOutputStream 1.4 |
|
|
I have tried a class from Chen but it seems impossible to add something to a
jar without erasing what is in it.
I thought about unzipping evething adding the changes and rezipping
evrything.
Seems tiedous tome. Isn't there a method to add something to a jar?
"Québec" <jpda (AT) vidn (DOT) ca> wrote
| Quote: | Hi,
For sure Ifind theese jar things are intricated.
pw = new PrintWriter ( new
FileWriter(MusicCatalog.class.getResourceAsStream("catalog.txt") , true));
JPD
|
|
|
| Back to top |
|
 |
Jonas Kongslund Guest
|
Posted: Mon Nov 24, 2003 2:05 pm Post subject: Re: jarOutputStream 1.4 |
|
|
Québec wrote:
| Quote: | I have tried a class from Chen but it seems impossible to add something to
a jar without erasing what is in it.
|
jar uf <jar-file> <file1-to-add> <file2-to-add> ...
--
Jonas Kongslund
|
|
| Back to top |
|
 |
Québec Guest
|
Posted: Mon Nov 24, 2003 3:17 pm Post subject: Re: jarOutputStream 1.4 |
|
|
Sorry,
I am taking about this.
-------------------
System.out.println("Usage: java Main <jar-file> <file1>...");
-------------------
try {
// Create the manifest.
Manifest man = new Manifest();
man.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION,
"1.0");
for (int i=1; i<args.length; i++) {
File f = new File(args[i]);
Attributes attr = new Attributes();
attr.put(new Attributes.Name("Date"),
new Date(f.lastModified()).toString());
man.getEntries().put(entryName(f), attr);
}
// Dump manifest.
man.write(System.out);
JarOutputStream jos = new JarOutputStream(
new FileOutputStream(args[0]), man);
// Now save all the list files in the JAR.
byte[] buf = new byte[1024];
int len;
for (int i=1; i
File f = new File(args[i]);
FileInputStream fis = new FileInputStream(f);
jos.putNextEntry(new JarEntry(entryName(f)));
// Now read and write the jar entry data.
while ((len = fis.read(buf)) >= 0) {
jos.write(buf, 0, len);
}
fis.close();
}
jos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// Converts f's pathname to a form acceptable to ZIP files.
// In particular, file separators are converted to forward slashes.
static String entryName(File f) throws IOException {
return f.getName().replace(File.separatorChar, '/');
}
}
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|