Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to create a JAR file
Dear everyone,
I need to write a method that takes a source directory and jars its
content. I wrote the following:
public static void jar(String sourceDir,JarOutputStream out,String
parent){
try {
// get a list of files from the current directory
File f = new File(sourceDir);
String files[] = f.list();
// update the parent
if (parent != ""){
parent = parent + File.separatorChar;
}
File tempFile;
BufferedInputStream origin = null;
byte data[] = new byte[2048];
for (int i=0; i<files.length; i++) {
System.out.println("Adding: " + files[i]);
tempFile = new File(sourceDir +File.separatorChar + files[i]);
if(tempFile.isFile()){
FileInputStream fi = new FileInputStream(sourceDir +
File.separatorChar + files[i]);
origin = new BufferedInputStream(fi, 2048);
JarEntry entry = new JarEntry(parent + files[i]);
out.putNextEntry(entry);
int count;
while((count = origin.read(data, 0, 2048)) != -1) {
out.write(data, 0, count);
}
origin.close();
}
else{
JarEntry entry = new JarEntry(parent + files[i] + File.separatorChar);
out.putNextEntry(entry);
jar(sourceDir + File.separatorChar + files[i],out, parent + files[i]);
}
}
} catch(Exception e) {
e.printStackTrace();
}
}

The problem with the code is the following:

1. Each subdirectory contains an extra empty file
2. If you try to extract a jar file created by this method. The entry
of a subdirectory is considered as a file not a directory.
3. I don't know how to create the META-INF folder

I would appreciate your help sooooo much. Regards, Samar

Report this thread to moderator Post Follow-up to this message
Old Post
Samar Hossam
10-24-04 01:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:57 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.