This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JAR File  RSS feed

 
kalai sundar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • 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
 
Osuwari Inu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Sorry, my bad. Just found out that this forum ignores leading blanks
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!