import java.util.zip.*;public class Trycompressedprimesoutput
{
public static void main(String[] args)
{
// Create application frame.
long primes =new long[200];
primes[0]=2;
primes[1]=3;
int count=2;
long number=5;
outer:
for(;count<primes.length;number+=2l)
{
long limit=(long)Math.ceil(Math.sqrt((double)number));
for(int i=1;i<count&&primes[i]<=limit;i++)
if(number%primes[i]==0)
continue outer;
primes[count++]=number;
}
try
{
String dirname="d:\\javawork";
String zipname="newprimes.zip";
String filename="newprimes.bin";
File myprimeDir=new File(dirname);
if(!myprimeDir.exists())
myprimeDir.mkdir();
else
if(!myprimesDir.isDirectory())
{
System.out.println(dirname+"is a directory");
return;
}
File muprimezip=new File(myprimeDir,zipname);
Myprimezip.createnewFile();
ZipoutputStream myzipFile=new ZipoutputStream(
new FileoutputStream(myprimezip));
ZipEntry myzipEntry= new ZipEntry(filename);
myzipFile.putNextEntry(myZipEntry);
DataoutputStream myFlie= new DataoutputStream(
new BufferedoutputSream(myZipFile));
for(int i=0;i<primes.length;i++)
myFile.writelong(primes[i]);
myFile.flush();
myZipFile.closeEntry();
myFile.close();
System.out.println("File size ="+myFile.size());
System.out.println("compressed file size=" + myZipEntry.getcompressedsize());
}
catch(IOException e)
{
System.out.println("IOException" + e +"occurred");
}
}
}
提示的错误是javac: invalid flag: Trycompressedprimesoutput
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag>
谢谢了,因为是初学,不太懂压缩的用法,我的是什么哪里错了,就不清楚
{
public static void main(String[] args)
{
// Create application frame.
long primes =new long[200];
primes[0]=2;
primes[1]=3;
int count=2;
long number=5;
outer:
for(;count<primes.length;number+=2l)
{
long limit=(long)Math.ceil(Math.sqrt((double)number));
for(int i=1;i<count&&primes[i]<=limit;i++)
if(number%primes[i]==0)
continue outer;
primes[count++]=number;
}
try
{
String dirname="d:\\javawork";
String zipname="newprimes.zip";
String filename="newprimes.bin";
File myprimeDir=new File(dirname);
if(!myprimeDir.exists())
myprimeDir.mkdir();
else
if(!myprimesDir.isDirectory())
{
System.out.println(dirname+"is a directory");
return;
}
File muprimezip=new File(myprimeDir,zipname);
Myprimezip.createnewFile();
ZipoutputStream myzipFile=new ZipoutputStream(
new FileoutputStream(myprimezip));
ZipEntry myzipEntry= new ZipEntry(filename);
myzipFile.putNextEntry(myZipEntry);
DataoutputStream myFlie= new DataoutputStream(
new BufferedoutputSream(myZipFile));
for(int i=0;i<primes.length;i++)
myFile.writelong(primes[i]);
myFile.flush();
myZipFile.closeEntry();
myFile.close();
System.out.println("File size ="+myFile.size());
System.out.println("compressed file size=" + myZipEntry.getcompressedsize());
}
catch(IOException e)
{
System.out.println("IOException" + e +"occurred");
}
}
}
提示的错误是javac: invalid flag: Trycompressedprimesoutput
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag>
谢谢了,因为是初学,不太懂压缩的用法,我的是什么哪里错了,就不清楚
javac的参数是你要编译的原文件的文件的全名
假如你的代码保存为Trycompressedprimesoutput.java则:
使用:javac Trycompressedprimesoutput.java进行编译
你的大小字母的问题太多import java.util.zip.*;
import java.io.File;//修改,导入File类,代码中有使用。
import java.io.IOException;
import java.io.FileOutputStream;public class Trycompressedprimesoutput
{
public static void main(String[] args)
{
// Create application frame.
long[] primes =new long[200];//修改,需要一个long的数组,long primes只能定义一个long型变量。
primes[0]=2;
primes[1]=3;
int count=2;
long number=5;
outer:
for(;count<primes.length;number+=2l)
{
long limit=(long)Math.ceil(Math.sqrt((double)number));
for(int i=1;i<count&&primes[i]<=limit;i++)
if(number%primes[i]==0)
continue outer;
primes[count++]=number;
}
try
{
String dirname="d:\\javawork";
String zipname="newprimes.zip";
String filename="newprimes.bin";
File myprimeDir=new File(dirname);
if(!myprimeDir.exists())
myprimeDir.mkdir();
else
if(!myprimeDir.isDirectory())//修改,变量名写错了,与前面申明的不一致
{
System.out.println(dirname+"is a directory");
return;
}
File myprimezip=new File(myprimeDir,zipname);
//修改,muprimezip应该为myprimezip;
myprimezip.createNewFile();
//修改,Myprimezip.createnewFile()应该为myprimezip.createNewFile();
ZipOutputStream myzipFile=new ZipOutputStream(
new FileOutputStream(myprimezip));
//修改,ZipoutputStream应该为ZipOutputStream,FileoutputStream应该为FileOutputStream
ZipEntry myzipEntry= new ZipEntry(filename);
myzipFile.putNextEntry(myzipEntry);
//修改,myzipEntry改为myzipEntry;
DataOutputStream myFile= new DataOutputStream(
new BufferedoutputSream(myZipFile));
//修改,myFlie书写错误,改为myFile;DataoutputStream改为DataOutputStream
for(int i=0;i<primes.length;i++)
myFile.writelong(primes[i]);
myFile.flush();
myzipFile.closeEntry();
//修改,根据前面的定义myZipFile应该为myzipFile;
myFile.close();
System.out.println("File size ="+myFile.size());
System.out.println("compressed file size=" + myzipEntry.getcompressedsize());
//修改,根据前面的定义myZipEntry应该为myzipEntry;
}
catch(IOException e)
{
System.out.println("IOException" + e +"occurred");
}
}
}