请完成下列Java程序:读取自己的源文件并把它压缩成GZIP文件。
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
import java.io.*;
import java.util.zip.*;
public class exl6 2 {
public static void main{String[] arg) {
ex16_2 obj16_2 = new ex16_2();
obj16_2.doZip("ex16_2.java","ex16_2.gzip")
}
public void doZip(String strIn,String strOut
FileInputStream in;
FileOutputStream out;
GZIPOutputStream gzip;
int nFileLength;
byte[] barray = new byte[10];
try {
in = new FileInputStream(strIn);
out = new FileOutputStream(strOut);
gzip = new GZIPOutputStream(out);
while((nFileLength = in.read(barray, 0 barray.length)) > 0)
_____________________;
______________________;
gzip.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
第1题:
请完成下列Java程序。程序的功能是显示用户在命令行方式下指定的任意驱动器目录的内容。
(提示:public String[]list();//将目录中所有文件名保存在字符数组中返回)
注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
import java.io.*;
public class FindDirectories
{
public static void main(String args[]
{
if(args.length==0)
args=new String[]{".."};
try
{
_______________
String[] fileName=pathName.list();
for(int i=0;i<fileName.length;i++
{
File f=new File(pathName.getPath() fileName[i]);
if(___________________)
{
System.out.println(f.getCanonicalPath());
main(new String[]
{
f.getPath()
});
}
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
第2题:
编写函数fun,它的功能是计算下列级数和,和值由函数值返回。
例如,当n=10,x=0.3时,函数值为1.349859。
注意:部分源程序在文件PROGl.C文件中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
第3题:
Java应用程序源文件中最多只能有()个main方法。
第4题:
请完成下列Java程序。程序的输出结果:a=6,b=5。
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
程序运行结果如下:
public class ex38_2{
public static void main(String args[])
{
int a=5,b=6;
a=_________;
b=a-b;
a=_________;
System.out.println("a="+a+"\tb="+b);
}
}
第5题:
请编写一个函数fun,它的功能是:根据以下公式求π的值(要求满足精度0.0005,即某项小于0.0005时停止迭代):
程序运行后,如果输入精度0.0005,则程序输出为3.140578。
注意:部分源程序存在文件PROGl.C文件中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。