Reader
DataOutputStream
ByteArrayInputStream
InputStreamReader
第1题:
请完成下列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();
}
}
}
第2题:
下列Java语句从指定网址读取html文件,在下画线处应填上的选项是( )。 Reader in=new (new URL(urlString). openStream);
A.Reader
B.DataOutputStream
C.ByteArray InputStream
D.InputStreamReader
第3题:
下列Java语句从指定网址读取html文件,在下划线处应填上的选项是( )。 Readerin=new______(newURL(urlString).openStream());
A.Reader
B.DataOutputStream
C.ByteArraylnputStream
D.InputStreamReader
第4题:
为使下列代码正常运行,应该在下画线处填入的选项是( )。
A.Reader
B.InputStream
C.ObjectInput
D.ObjectInputStream
第5题:
下面Java语句从指定的网址读取HTML文件,在下画线处应填上的选项是 Reader in=new______(new URL(urlString).openStrream());
A.Reader
B.DataOutputStream
C.ByteArrayInputStream
D.InputStreamReader
第6题:
阅读下列 Java 语句
ObjectOutputStream out
New ObjectOutputStream {new_______( “ employee.dat ” )};
在下划线处,应填的正确选项是
A ) File
B ) FileWriter
C ) FileOutputStream
D ) OutputStream
第7题:
阅读下面Java语句 ObjectOutputStream ut=new ObjectOutputStream(new______("employee.dat"));在下画线处,应填的正确选项是
A.File
B.FileWriter
C.FileOutputStream
D.OutputStream
第8题:
为使下列代码正常运行,应该在下划线处填入的选项是
ObjectInputStream in=
new_____(new FileInputStream(“employee . dat”));
Employee[]newStaff=(Employee[〕)in.readObject();
in .cIose();
A.Reader
B.InputStream
C.ObjectInput
D.ObjectInputStream
第9题:
在程序中,用户输入一个文件名,根据用户输入显示相应文件的信息。
注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。
______java.io.*;
public class basic
{
public static void main(String[] args)
{
InputStreamReader reader;
BufferedReader in;
System.out.println("请输入文件名: ");
try
{
reader=new InputStreamReader(______);
in=new BufferedReader(reader);
String filename=in.readLine();
File file=new File(filename);
System.out.println("文件名:"+file.______);
System.out.println("路径:"+file.getAbsolutePath());
System.out.println("大小:"+file.length());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
第10题:
请完成下列Java程序:读取新浪首页文件的数据并且显示出来。要求编写JFrame扩展类,以String类的对象定义的url地址作为入口参数,该类实现根据url参数指定的地址进行连接和读取数据,并且能显示在1个文本区域内。
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
程序运行结果如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class ex25_2 {
public static void main(String[] arg) {
UrlFrame. page = new UrlFrame("http://www.sina.com.cn");
page.show();
}
}
class UrlFrame. extends JFrame. {
JTextArea jta = new JmextArea("正在读取文件…");
URL url;
public UrlFrame(String strAddr) {
super (strAddr); //使用父类的构造方法。
setSize(450, 300);
JScrollPane jsp = new JScrollPane(jta);
getContentPane().add(jsp);
WindowListener wl = new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
};
addWindowListener(wl);
try {
url = new URL(strAddr);
____________________;
} catch (MalformedURLException murle) {
System.out.println("不合适的URL: "+ strAddr);
}
}
void getData(URL url) {
URLConnection con = null;
InputStreamReader isr;
BufferedReader readBuf;
String strLine;
StringBuffer strBuf = new StringBuffer();
try {
con = this.url.openConnection();
con.connect();
jta.setText("打开连接...");
isr = new InputStreamReader(con.getInputStream( ));
readBuf = new BufferedReader(isr);
jta.setText("读取数据...");
while ((strLine = readBuf.readLine()) != null)
strBuf.append(strLine + "\n");
_____________________________;
} catch (IOException e) {
System.out.println("IO 错误:" + e.getMessage());
}
}
}