AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

printing to a txt file in a jar

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Québec
Guest





PostPosted: Sun Nov 23, 2003 2:51 pm    Post subject: printing to a txt file in a jar Reply with 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
Québec
Guest





PostPosted: Mon Nov 24, 2003 1:09 pm    Post subject: jarOutputStream 1.4 Reply with quote



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





PostPosted: Mon Nov 24, 2003 2:05 pm    Post subject: Re: jarOutputStream 1.4 Reply with quote



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





PostPosted: Mon Nov 24, 2003 3:17 pm    Post subject: Re: jarOutputStream 1.4 Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.