我的目标是对文件进行编码并将其压缩到java中的文件夹中.我必须使用Apache的Commons-codec库.我能够编码和压缩它并且它工作正常但是当我将其解码回原始形式时,看起来该文件尚未完全编码.看起来缺少一些零件.谁能告诉我为什么会这样?
我还附上了我的代码部分供您参考,以便您可以相应地指导我.
private void zip() {
int BUFFER_SIZE = 4096;
byte[] buffer = new byte[BUFFER_SIZE];
try {
// Create the ZIP file
String outFilename = "H:\\OUTPUT.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
outFilename));
// Compress the files
for (int i : list.getSelectedIndices()) {
System.out.println(vector.elementAt(i));
FileInputStream in = new FileInputStream(vector.elementAt(i));
File f = vector.elementAt(i);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(f.getName()));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buffer)) > 0) …Run Code Online (Sandbox Code Playgroud) 我想为像"S67-90"这样的字符串生成一个正则表达式.我使用了语法"String pattern ="\ w\d\d\W\d\d"",但我想指定第一个单词字符应始终以"S"开头.有人可以帮帮我吗?
我的示例代码是:
String pattern = "\\w\\d\\d\\W\\d\\d";
Pattern p = Pattern.compile((pattern));
Matcher m = p.matcher(result);
if (m.find()) {
System.out.println("Yes!It is!");
}
else{
System.out.println("No!Its not :(");
}
Run Code Online (Sandbox Code Playgroud)