こんにちは、私はjavaに新しいです。Deflater
をjava.util.zip
で使用してバイトストリームを圧縮しようとしています。私はOracle siteの例に従っています。私はこのコードを実行するとDeflaterをjava.util.zipで使用する方法
try {
// Encode a String into bytes
String inputString = "blahblahblah";
byte[] input = inputString.getBytes("UTF-8");
// Compress the bytes
byte[] output = new byte[100];
Deflater compresser = new Deflater();
compresser.setInput(input);
compresser.finish();
int compressedDataLength = compresser.deflate(output);
compresser.end();
// Decompress the bytes
Inflater decompresser = new Inflater();
decompresser.setInput(output, 0, compressedDataLength);
byte[] result = new byte[100];
int resultLength = decompresser.inflate(result);
decompresser.end();
// Decode the bytes into a String
String outputString = new String(result, 0, resultLength, "UTF-8");
} catch(java.io.UnsupportedEncodingException ex) {
// handle
} catch (java.util.zip.DataFormatException ex) {
// handle
}
それはsetInput()
、finish()
、deflate()
とend()
が定義されていないと言って私にエラーを与えます。ここでは、エラーメッセージが私はjava.util.zip
をインポートし、Oracle site.Itでドキュメントに見えた
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)
でこれらのメソッドが存在すると言います。
問題のある場所を特定できません。誰かが助けることができる?
私はチュートリアルポイントで全く同じコードをオンラインで実行し、それは完全に機能しました。メソッドはDeflateクラスにあります。 Javaセットアップにエラーがありますか?InflateとDeflateを別々にインポートしてみてください。 –