Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Regarding zip files in java [modified]

Regarding zip files in java [modified]

Scheduled Pinned Locked Moved Java
c++javahelpquestion
5 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chinnasri
    wrote on last edited by
    #1

    Hi , ANYONE LET ME KNOW WHAT IS GOING WRONG HER, I AM TRYING TO CREATE ZIP FILE IN JAVA, BUE IAM GETTING THE ERROR AS FALLOWS, GO THRU THE CODE ALSO WHAT I WROTE import java.util.zip.*;import java.io.*; public class ZipFileExample { public static void main(String args[])throws IOException { FileInputStream fis=new FileInputStream("Allpaths.txt"); FileOutputStream fos=new FileOutputStream("kkk.txt"); DeflaterOutputStream dos=new DeflaterOutputStream(fos); int data; while((data=fis.read())!=-1){ dos.write(data); fis.close(); dos.close(); } } } eRROR: Exception in thread "main" java.io.FileNotFoundException: Allpaths.txt (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(Unknown Source) at java.io.FileInputStream.<init>(Unknown Source) at ZipFileExample.main(ZipFileExample.java:4)

    modified on Thursday, July 16, 2009 11:06 PM

    L D 2 Replies Last reply
    0
    • C chinnasri

      Hi , ANYONE LET ME KNOW WHAT IS GOING WRONG HER, I AM TRYING TO CREATE ZIP FILE IN JAVA, BUE IAM GETTING THE ERROR AS FALLOWS, GO THRU THE CODE ALSO WHAT I WROTE import java.util.zip.*;import java.io.*; public class ZipFileExample { public static void main(String args[])throws IOException { FileInputStream fis=new FileInputStream("Allpaths.txt"); FileOutputStream fos=new FileOutputStream("kkk.txt"); DeflaterOutputStream dos=new DeflaterOutputStream(fos); int data; while((data=fis.read())!=-1){ dos.write(data); fis.close(); dos.close(); } } } eRROR: Exception in thread "main" java.io.FileNotFoundException: Allpaths.txt (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(Unknown Source) at java.io.FileInputStream.<init>(Unknown Source) at ZipFileExample.main(ZipFileExample.java:4)

      modified on Thursday, July 16, 2009 11:06 PM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Hi, please check your Caps lock. And use pre tags. Anyway, are you sure "Allpaths.txt" exists? Of course you are, otherwise you wouldn't be posting here with ALL CAPS, but would you check it again? And that while loop looks fishy. Where is the closing }? I think it should be after the dos.write, but in this case you would accomplish the same by removing the opening {. This shouldn't even compile, but putting the } after dos.close is pretty much guaranteed to be wrong.

      C 1 Reply Last reply
      0
      • L Lost User

        Hi, please check your Caps lock. And use pre tags. Anyway, are you sure "Allpaths.txt" exists? Of course you are, otherwise you wouldn't be posting here with ALL CAPS, but would you check it again? And that while loop looks fishy. Where is the closing }? I think it should be after the dos.write, but in this case you would accomplish the same by removing the opening {. This shouldn't even compile, but putting the } after dos.close is pretty much guaranteed to be wrong.

        C Offline
        C Offline
        chinnasri
        wrote on last edited by
        #3

        i closed properlly, eventhough iam getting same problem

        L 1 Reply Last reply
        0
        • C chinnasri

          i closed properlly, eventhough iam getting same problem

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          chinnasri wrote:

          i closed properlly

          No you didn't, you only closed in a way that would compile, not in the way that you should close. But anyway, the problem is not caused by the weird closing - the problem happens before that. But if you don't fix the closing, it will be your next problem. Or maybe there will be something in between, but eventually it will be a problem if you leave it like this. Please verify that the file that you are opening actually exists.

          1 Reply Last reply
          0
          • C chinnasri

            Hi , ANYONE LET ME KNOW WHAT IS GOING WRONG HER, I AM TRYING TO CREATE ZIP FILE IN JAVA, BUE IAM GETTING THE ERROR AS FALLOWS, GO THRU THE CODE ALSO WHAT I WROTE import java.util.zip.*;import java.io.*; public class ZipFileExample { public static void main(String args[])throws IOException { FileInputStream fis=new FileInputStream("Allpaths.txt"); FileOutputStream fos=new FileOutputStream("kkk.txt"); DeflaterOutputStream dos=new DeflaterOutputStream(fos); int data; while((data=fis.read())!=-1){ dos.write(data); fis.close(); dos.close(); } } } eRROR: Exception in thread "main" java.io.FileNotFoundException: Allpaths.txt (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(Unknown Source) at java.io.FileInputStream.<init>(Unknown Source) at ZipFileExample.main(ZipFileExample.java:4)

            modified on Thursday, July 16, 2009 11:06 PM

            D Offline
            D Offline
            David Skelly
            wrote on last edited by
            #5

            The documentation for FileInputStream is very clear, if you read it:

            If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown.

            So, either make sure that Allpaths.txt is in the classpath for your application, or specify the full path to its location. Your while loop is wrong. You close the input stream during the first iteration through the loop, immediately after writing to the deflater. So, the second time you try to read from it, it will fail because it is no longer open.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups