好像文件导入不进去,不知哪出错,怎么修改!
部分界面代码:
public void actionPerformed(ActionEvent arg0) {
if (arg0.getSource() == btn3) {
liulan1.setMultiSelectionEnabled(true);
int m = liulan1.showOpenDialog(null);
if (m == JFileChooser.APPROVE_OPTION) {
File sourceDIR=liulan1.getSelectedFile();
importf.setText(sourceDIR.getAbsolutePath());
}
}
if (arg0.getSource() == btn4){
liulan2.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
liulan2.setMultiSelectionEnabled(true);
int n = liulan2.showOpenDialog(null);
if (n == JFileChooser.APPROVE_OPTION) {
File targetZipFile =liulan2.getSelectedFile();
exportf.setText(targetZipFile.getAbsolutePath());
}
}
if (arg0.getSource()==btn1){
String save1="";
String save2="";
if(sourceDIR!=null){
save1=sourceDIR.getAbsolutePath()+"/"+sourceDIR.getName();
save2=targetZipFile.getAbsolutePath()+"/"+sourceDIR.getName()+".zip";
}
new gzip(save1,save2);
}
if (arg0.getSource()==btn2){
String save1="";
String save2="";
if(sourceDIR!=null){
save1=sourceDIR.getAbsolutePath()+"/"+sourceDIR.getName().replaceAll("zip","");
save2=targetZipFile.getAbsolutePath()+"/"+sourceDIR.getName();
}
//if(targetZipFile.getName().lastIndexOf("zip")>0){
new ungzip(save1,save2);
//}
}
}
调用的主程序代码:
package 主类;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
public class gzip
{
public gzip(String save1,String save2){
if(save1.length()+save1.length()!= 2)
{
System.out.println("Usage:java gzip ");
}
try
{
int num;
FileInputStream fin = new FileInputStream(save1);
FileOutputStream fout = new FileOutputStream(save1);
GZIPOutputStream gzout = new GZIPOutputStream(fout);
byte[] buf = new byte[1024];
while ((num = fin.read(buf)) != -1)
{
gzout.write(buf, 0, num);
}
gzout.close();
fout.close();
fin.close();
}
catch (IOException e) {
System.out.println(e);
}
}
}
单独这样是可以运行的,但我放界面,改了参数,导文件进去,就没反应了
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
public class gzip
{
public gzip(String args[]){
if(args.length!= 2)
{
System.out.println("Usage:java gzip ");
}
try
{
int num;
FileInputStream fin = new FileInputStream(args[0]);
FileOutputStream fout = new FileOutputStream(args[0]);
GZIPOutputStream gzout = new GZIPOutputStream(fout);
byte[] buf = new byte[1024];
while ((num = fin.read(buf)) != -1)
{
gzout.write(buf, 0, num);
}
gzout.close();
fout.close();
fin.close();
}
catch (IOException e) {
System.out.println(e);
}
}
}