⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readzippedprimes.java

📁 Java Classic Examples是我买的两本书:《JAVA经典实例》和《java入门经典源代码》里边附送光盘里带的源码
💻 JAVA
字号:
import java.io.*;
import java.util.zip.*;

class ReadZippedPrimes
{
  public static void main(String[] args)
  {
    try
    {
      // Create a default formatted character output stream 
      FormatWriter out = new FormatWriter(
                         new BufferedWriter(
                         new FileWriter(FileDescriptor.out)));

      String dirName = "c:\\JunkData";    // Directory for the ZIP file
      String zipName = "NewPrimes.zip";   // The ZIP archive name

      File myPrimeZip = new File(dirName, zipName);  // The file object
      ZipInputStream myZipFile = new ZipInputStream(
                                        new FileInputStream(myPrimeZip));
      ZipEntry myZipEntry = myZipFile.getNextEntry(); 

      out.println("Compressed File is " + myZipEntry.getName());
      DataInputStream primesIn = new DataInputStream(
                                 new BufferedInputStream(myZipFile));

      long[] primes = new long[6];        // Array for one line of primes
      boolean EOF = false;                // End of file flag
      
      while(!EOF)
      {
        int index = 0;                    // Index for storing primes 
        try
        {
          // Fill the array with primes from the file
          for(index = 0; index < primes.length; index++)
            primes[index] = primesIn.readLong();
        }
        catch(EOFException e)
        {
          EOF = true;                      // This will end the while loop
        }
        // Output the number of primes in the array
        for(int j = 0; j < index; j++)
          out.print(primes[j]);
        out.println();                      // Write end of line
      }

      out.close();                          // Flush and close the output stream
      primesIn.close();                     // Close the input stream
    }
    catch(FileNotFoundException e)          // Stream creation exception
    {
      System.err.println(e);
      return;
    }
    catch(IOException e)                    // File read exception
    {
      System.out.println("Error reading input file" + e );
      return;
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -