试题与答案

在程序中,用户输入一个文件名,根据用户输入显示相应文件的信息。 注意:请勿修改ma

题型:问答题

题目:

在程序中,用户输入一个文件名,根据用户输入显示相应文件的信息。
注意:请勿修改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();


答案:

参考答案:import
System.in
getName()

解析:[讲解] 本题考查知识点:Java类库中常用类和接口、文件和文件I/0、输入输出。解题思路:题中reader从系统获得输入流,从这个流中得到用户输入的字符串作为文件名,找到文件,进而得到文件的相关信息。Java的类库需要引入以后才能使用,关键字import就是声明需要引入的类或包。因此第1个空的答案是import。Java的输入输出是以流的形式来完成的。InputStreamReader的对象reader从系统输入中读取输入流,保存在相应的缓冲区中,因此第2个空的答案是System.in。BufferedReader对象则是从这个缓冲区中读取数据,使用BufferedReader类的readLine()方法即可获得输入流中的一行输入。在Java程序中,文件作为类的一个实例来处理,File类具有很多与文件相关的方法,比如获得上级目录名(getParent()方法)、路径(getPath()方法)等,第3个空就是使用getName()方法获取文件的文件名。

试题推荐
题型:完形填空
完形填空。
     In 1977, a dead author of detective stories saved the life of a 19-month-old baby in a most unusual way.
The author was Agatha Christie, one of the most successful writers of detective stories in the world.
     In June 1977, a baby girl became seriously ill in Qatar, near Saudi Arabia. Doctors were unable to   1   
the cause of her illness, so she   2   to London and admitted to Hammersmith Hospital, where specialist help
was   3  . She was then only half-conscious (半昏迷) and on the "Dangerously Ill" list. A team of doctors
hurried to   4   the baby only to discover that they,   5  , were puzzled by the very unusual symptoms. While
they were discussing the baby's case, a nurse asked to   6   to them.
     "Excuse me," said nurse Marsha Maitland, "  7   I think the baby is   8   from thallium poisoning."
     "  9   makes you think that?" Dr. Brown asked. "Thallium poisoning is extremely  10  ."
     "A few days ago, I was reading a novel called A Pale Horse  11  Agatha Christie," Nurse Maitland explained.
"In the book, somebody uses thallium poison, and  12  the symptoms are  13 . They are exactly the same as the
baby's."
     "You're very observant and you may be right," another doctor said. "We'll  14  some tests and find out  15 
 it's thallium or not."
     The  16  showed that the baby had  17  been poisoned by thallium, a rare metal used in making optical (光学
的) glass.  18  they knew the cause of illness, the doctors were able to give the correct treatment. The baby
soon  19  and was sent back to Qatar. Inquiries (调查) showed that the poison  20  from an insecticide (杀虫剂)
used in Qatar.
( )1. A. describe    
( )2. A. flew       
( )3. A. inexpensive 
( )4. A. examine    
( )5. A. too       
( )6. A. refer      
( )7. A. and       
( )8. A. coming      
( )9. A. Who       
( )10. A. rare       
( )11. A. in         
( )12. A. all         
( )13. A. drawn       
( )14. A. ma ke up    
( )15. A. that       
( )16. A. words       
( )17. A. indeed      
( )18. A. As long as   
( )19. A. died       
( )20. A. must come    
B. diagnose   
B. sent      
B. important  
B. see     
B. either    
B. turn      
B. so       
B. suffering  
B. How     
B. serious   
B. on       
B. some of  
B. broadcast 
B. carry out  
B. how     
B. tests    
B. actually   
B. As for as  
B. got injured 
B. should come      
C. discover       
C. went          
C. available     
C. look after     
C. often          
C. speak        
C. as            
C. tired        
C. What          
C. clear        
C. by            
C. one of        
C. announced     
C. get through    
C. what          
C. examination    
C. probably       
C. Once          
C. recovered     
C. might have come    
D. discuss              
D. was flown            
D. impossible           
D. cure                 
D. never                
D. belong               
D. but                  
D. dying                
D. Which                
D. dangerous            
D. about                
D. both                 
D. described                         
D. deal with            
D. whether              
D. book                 
D. never                
D. If                   
D. got ill              
D. can’t have come     
查看答案
微信公众账号搜索答案