Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Issue in Converting .zip file to .jar file?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Saravanan
Issue in Converting .zip file to .jar file?
1 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners


I have a folder called "printpdf.jar". I have changed the .jar to .zip and did some customizations. After which i had "zipped" it again and made as ".jar". Now the final file is displayed in executable icon rather then text editor icon. How do i make it display in text editor icon.


Advertisement
View Answers

April 19, 2011 at 4:55 PM


import java.io.*;
import java.util.*;
import java.util.jar.*;
import java.util.zip.*;

public class ConvertZipToJar{
public static void main(String[]args)throws Exception{
byte b[] = new byte[10240];
FileOutputStream fout = new FileOutputStream(new File("C:/TextExamples.jar"));
JarOutputStream out = new JarOutputStream(fout, new Manifest());
ZipFile zf = new ZipFile("C:/TextExamples.zip");
Enumeration entries = zf.entries();
while(entries.hasMoreElements()){
ZipEntry ze = (ZipEntry) entries.nextElement();
System.out.println("Adding " + ze.getName());
JarEntry addFiles = new JarEntry(ze.getName());
out.putNextEntry(addFiles);
      long size = ze.getSize();
          if (size > 0){
            System.out.println("Length is " + size);
            BufferedReader br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze))); 
            String line;
            while((line = br.readLine()) != null) {
              System.out.println(line);
              out.write(line.getBytes());
            }
             br.close();
          }
}
out.close();
fout.close();
}
}


Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com