Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java.util.zip中使用Deflater_Java_Zip_Deflate - Fatal编程技术网

如何在java.util.zip中使用Deflater

如何在java.util.zip中使用Deflater,java,zip,deflate,Java,Zip,Deflate,大家好,我是java新手,我正在尝试使用java.util.zip中的Deflater压缩字节流 运行此代码时,会出现一个错误,说明未定义setInput()、finish()、deflate()和end()。这是错误消息 Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method setInput(byte[]) is undefined for the type Deflat

大家好,我是java新手,我正在尝试使用
java.util.zip
中的
Deflater
压缩字节流

运行此代码时,会出现一个错误,说明未定义
setInput()
finish()
deflate()
end()
。这是错误消息

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The method setInput(byte[]) is undefined for the type Deflater
The method finish() is undefined for the type Deflater
The method deflate(byte[]) is undefined for the type Deflater
The method end() is undefined for the type Deflater

at Deflater.main(Deflater.java:16)
我导入了
java.util.zip
并查看了Oracle站点中的文档。它说这些方法是存在的


我想不出问题出在哪里。有人能帮忙吗。

问题是您正在调用您的主类
Deflater
,这对编译器来说是不明确的。有两个名称相同的类,您的类和Zip
Deflater
。您应该更改此行:
Deflater compresser=new Deflater()
到这个
java.util.zip.Deflater compresser=new java.util.zip.Deflater()或只需更改主类的名称。

我在tutorials point上在线执行了完全相同的代码,效果非常好,方法出现在Deflate类中。如果java设置中存在错误,请尝试分别导入充气和放气。
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The method setInput(byte[]) is undefined for the type Deflater
The method finish() is undefined for the type Deflater
The method deflate(byte[]) is undefined for the type Deflater
The method end() is undefined for the type Deflater

at Deflater.main(Deflater.java:16)