题目内容 (请给出正确答案)
[主观题]

下面程序的功能是从键盘读取一行文本并将该文本存储到文件中。当用户运行该程序时,需要输入一行文

本并按下回车键。然后在DOS系统提示符处输入type file.txt并按下Enter键,这时屏幕会显示type file.txt的内容。通过这个命令可以验证该程序的功能。请在每条横线处填写一条语句,使程序的功能完整。

注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。

源程序文件代码清单如下:

import java.io.*;

public class DoFile

{

public static void main(String args[])

{

byte buffername[]=______[80];

try

{

System.out.println("\nEnter a line to be saved to disk:");

int bytesbleck= ______;

FileOutputStream f=new FileOutputStream("file.txt");

______;

}

catch(Exception e)

{

e.printStackTrace();

}

}

}

查看答案
如搜索结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能会需要:
您的账号:
发送账号密码至手机
发送
更多“下面程序的功能是从键盘读取一行文本并将该文本存储到文件中。当…”相关的问题

第1题

下面程序执行结果为:1×1=12×1=22×2=43×1=33×2=63×3=99×1=99×2=189×3=279×4=36 9×5=459×6=549×7=6

下面程序执行结果为:

1×1=1

2×1=2 2×2=4

3×1=3 3×2=6 3×3=9

9×1=9 9×2=18 9×3=27 9×4=36 9×5=45 9×6=54 9×7=63 9×8=72 9×9=81

请在每条横线处填写一个语句,使程序的功能完整。

注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。

public class ForLoopStatement{

public static void main(String args[]){

int m,n;

for(m=1;m<10;_____________)

________________;

System.out.print(m+ "*" + n + "=" + m * n + " " );

_____________}

}

点击查看答案

第2题

请完成下列Java程序:生成一个窗口,包含一个长度为100的横向滚动条,实现对这个滚动条状态的监视,

计算出滚动条的位置在整个长度的百分比,并通过画布将该值输出在滚动条上方的区域中。

注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。

程序运行结果如下:

import java.awt.*;

import java.awt.event.*;

public class ex19_2 extends Frame. implements AdjustmentListener {

private Scrollbar sb;

private msgWnd mw;

private int val;

public static void main(String[] arg) {

ex19_2 obj19_2=new ex19_2();

}

public ex19_2() {

setTitle("ex19_2");

addWindowListener((WindowListener)new winListener());

mw = new msgWnd();

add("Center",mw);

sb = new Scrollbar(Scrollbar. HORIZONTAL);

sb.setVisibleAmount(10);

sb.setBlockIncrement(6);

sb.setUnitIncrement(5);

sb.addAdjustmentListener(this);

add("South",sb);

pack();

show();

}

public void adjustmentValueChanged(AdjustmentEvent ae) {

val = ae.getValue();

_______________;

}

class msgWnd extends Canvas {

msgWnd() {

setSize(450,20);

}

public void paint(Graphics g) (

g.drawString(" val=" +____________________+"%",10,15);

}

}

class winListener extends WindowAdapter {

public void windowClosing(WindowEvent we) {

System.exit(0);

}

}

}

点击查看答案

第3题

抽象类中含有没有实现的方法,该类不能【】。

抽象类中含有没有实现的方法,该类不能【 】。

点击查看答案

第4题

一棵二叉树有10个度为1的结点,7个度为2的结点,则该二义树共有【】个结点。

一棵二叉树有10个度为1的结点,7个度为2的结点,则该二义树共有【 】个结点。

点击查看答案

第5题

下列程序要求将source.txt文件中的字符,通过文件输入/输出流复制到另一个dest.txt文件中。请将程

序补充完整。

注意:不改动程序结构,不得增行或删行。

import java.io.*;

public class ex2

{

public static void main(String[] args) throws IOException

{

File inputFile;

File outputFile;

FileInputStream in;

FileOutputStream out;

int c;

inputFile=new File("source.txt");

utputFile=new File("dest.txt");

in=new FileInputStream(inputFile);

______(outputFile);

while((c=in.read())!=-1)

______;

in.close();

out.close();

}

}

点击查看答案

第6题

下列程序的功能是创建一个显示5个“Hello!”的线程并启动运行,试将程序补充完整。public class Thre

下列程序的功能是创建一个显示5个“Hello!”的线程并启动运行,试将程序补充完整。

public class ThreadTest extends Thread{

public static void main(String args[ ]){

ThreadTest t=new______;

t.start( );}

public void run( ){int i=0;

while(true){System.out.println("Hello!");

if(i++==4)break;

}

}

点击查看答案

第7题

关于文件名的处理,测试当前文件是否是目录用______函数。

点击查看答案

第8题

本程序的功能是,根据用户输入的文件名,在相应的文件内容中查找匹配给定模式的字符串,并将这些字

符串显示出来。模式串为“href="…"”。请填写横线处的内容。

注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。

import java.io.*;

import java.util.regex.*;

import javax.swing.*;

public class Example2_10

{

public static void main(String [] argv)

{

final String patternString =

"href\\s*=\\s*(\"[^\"]*\"|[^\\s>])\\s*;

String fileName ;

try

{

System. out. print ( "请输入html 文件的文件名: ");

InputStreamReader in = new InputStreamReader(System.in);

BufferedReader imput = new BufferedReader(in);

fileName = imput.readLine();

if(fileName.equals(" "))

return;

StringBuffer buffer = new StringBuffer();

File file = new File(fileName);

FileInputStream readfile = new FileInputStream(file);

for(int c = 0; (c = readfile.read()) != -1; )

buffer.append((char)c);

Pattern pattern = Pattern.compile(

_____________ Pattern.CASE_INSENSITIVE);

Matcher matcher =________;

while (marcher. find ())

{

int start = matcher.start();

int end = matcher.end();

String match = buffer.substring(start, end);

System.out.println (match);

}

}

catch (Exception excption)

{

System. out.println (excption. getMessage ());

}

System.exit(O);

}

}

点击查看答案

第9题

请在每条横线处填写一个语句,使程序的功能完整,且输出结果为91 1。 注意:请勿改动main()主方法和

请在每条横线处填写一个语句,使程序的功能完整,且输出结果为91 1。

注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。

源程序文件代码清单如下:

public class Outer

{

public static void main (String args[]

{

Outer i = new Outer();

i,taskInner();

}

public class Inner

{

private int size;

public void doSomething(int size)

{

_____________//访问局部变量

this. size++; //访问内部类的成员变量

_____________//访问外部类的成员变量

System.out.println(size+" "+this.size+" "+Outer.this.size);

}

}

public void taskInner()

{

___________

k.doSomething(8);

}

private static int size;

}

点击查看答案

第10题

清在下划线处填入代码,使程序正常运行并且输出“Hello!” classTesl______{ publicstaticvoidma

清在下划线处填入代码,使程序正常运行并且输出“Hello!”

classTesl______{

publicstaticvoidmain(string[]args){

Test=newTest();

t.start();

}

Pubhcvoidrun(){

System.out.println("Hello!");

}

}

点击查看答案
热门考试 全部 >
相关试卷 全部 >
账号:
你好,尊敬的上学吧用户
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
谢谢您的反馈

您认为本题答案有误,我们将认真、仔细核查,
如果您知道正确答案,欢迎您来纠错

警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
上学吧
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反上学吧购买须知被冻结。您可在“上学吧”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
上学吧
点击打开微信