• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

JAR File

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i created jsr file, my probm is if i give the input in directort structor i ma unable to create, my code is

protected void createJarArchive(File archiveFile, File[] tobeJared) {

try {

byte buffer[] = new byte[BUFFER_SIZE];
// Open archive file
FileOutputStream stream = new FileOutputStream(archiveFile);
System.out.println("The archive file name"+archiveFile);
JarOutputStream out = new JarOutputStream(stream, new Manifest());
for (int i = 0; i < tobeJared.length; i++) {
if(tobeJared[i].isDirectory()){

// if (tobeJared[i] == null || !tobeJared[i].exists()
// || tobeJared[i].isDirectory())
//continue; // Just in case...
System.out.println("Adding " + tobeJared[i].getName());

// Add archive entry
String s[] = tobeJared[i].list();
for(int j =0;j<s.length;j++){
File fi = new File(s[j]);
JarEntry jarAdd = new JarEntry(fi.getName());
jarAdd.setTime(fi.lastModified());
out.putNextEntry(jarAdd);

}
}
else{
JarEntry jarAdd = new JarEntry(tobeJared[i].getName());
jarAdd.setTime(tobeJared[i].lastModified());
out.putNextEntry(jarAdd);
}

// Write file to archive



// Write file to archive



FileInputStream in = new FileInputStream(tobeJared[i]);
while (true) {
int nRead = in.read(buffer, 0, buffer.length);
if (nRead <= 0)
break;
out.write(buffer, 0, nRead);
}
in.close();
}

out.close();
stream.close();
System.out.println("Adding completed OK");
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Error: " + ex.getMessage());
}
}
public static void main(String[] args)
{
jar cr=new jar();
File[] f=new File[5];
f[0]=new File("e:\\sample\\META-INF");
// f[0]=new File("e:\\sample\\bean.class");
f[1]=new File("e:\\sample\\home.class");
f[2]=new File("e:\\sample\\remote.class");
// f[3]=new File("e:\\sample\\META-INF");
// f[3]=new File("e:\\sample\\META-INF\\ejb-jar.xml");
// f[4]=new File("e:\\sample\\META-INF\\jboss.xml");
File sample=new File("e:\\sample\\temp\\njes.jar");
cr.createJarArchive(sample, f);
}
}


here my exception is The archive file namee:\sample\temp\njes.jar
Adding META-INF
Error: e:\sample\META-INF (Access is denied)
java.io.FileNotFoundException: e:\sample\META-INF (Access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at jar.createJarArchive(jar.java:52)
at jar.main(jar.java:82)

ca u hepl me plz
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i cant read this code please use interpunction in your questions and indent your code i doubt you will find anyone willing to try to help you if you drop it on them in a condition such as this i actually find it hard to type without any markup whatsoever i mean how do you do it?

Oh dang! I actually used a questionmark there.
 
Osuwari Inu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, my bad. Just found out that this forum ignores leading blanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic