问题 单项选择题

要从“file.dat”文件中读出第10个字节存到变量C中,下列______方法是合适的。

A.FileInputStream in=new FileInputStream("file.dat");in.skip(9);int c=in.read( );

B.FileInputStream in=new FileInputStream("file.dat");in.skip(10);int c=in.read( );

C.FileInputStream in=new FileInputStream("file.dat");int c=in.read( );

D.RandomAccessFile in=new RandomAccessFile("file.dat");in.skip(9);int c=in.readByte( );

答案

参考答案:A

解析: Java提供FileInputStream是将文件以流的方式读取,它是按照文件顺序从位置0开始读取的,RandomAccessFile是随机读取数据的;读取位置不一定从0开始,可以使用skip(n)方法来跳过n个字符,通过readByte( )方法读取一个字符,通过read( )方法可以读取输入流中的一个字符。所以要从第10个字节开始读取,应该用skip(10)方法,所以选项A正确。

完形填空
完形填空。

      Once upon a time, there were two men. One was hard-working and had a lot of   1   and perseverance
(坚定不移), while the other was   2   and never did any work. One night, they decided to have a competition
between them. The contest was simple: the   3   person to see daylight would be the winner, and the winner
would   4   a prize. Both men agree to do it, and the competition started.
      The hard-working man immediately   5   and ran towards the west after the sun, while the lazy man just
sat there and   6  . The hard-working man, looking at the competitor,   7   at his foolishness and kept going
at his quick pace. Running through the jungles, swimming   8   the rivers and seas, and he kept running and
running,   9   that he would reach his goal sooner or later. Meanwhile, the lazy man was still sleeping.
      The hard-working man had been  10  for 6 hours already, and he was surprised that he still had not  11  
daylight. Thinking it would be just around the corner, he  12  on running until he finally came back to where
he started, 24 hours  13 . Upon arriving, he saw the lazy man seated there, smiling and waiting for him,
holding the  14   he earned.
      The hard-working man was  15  how this lazy man could earn it-he hadn't done anything at all! Then the
lazy man said, "You are  16  a persevering and patient man, but you were running towards the  17 , running
after the sun that kept moving away from your  18  whereas I just waited for the sun to come to me. You
were lucky. If I had decided to  19  you and not to tell you, you would be continuing this pursuit till your
death." The hard-working man knew in his heart that the lazy man was right.
      Sometimes, perseverance can  20  you from the truth that what you are doing is wrong.

( )1. A. hobbies             
( )2. A. lazy                
( )3. A. last                
( )4. A. accept             
( )5. A. set in              
( )6. A. worked             
( )7. A. laughed            
( )8. A. across               
( )9. A. representing        
( )10. A. swimming           
( )11. A. admired             
( )12. A. commented          
( )13. A. before              
( )14. A. money               
( )15. A. believing           
( )16. A. true                
( )17. A. west                
( )18. A. ears               
( )19. A. hide from         
( )20. A. make                
B. ideas       
B. patient      
B. first      
B. keep        
B. set aside   
B. drank      
B. glared      
B. through     
B. believing    
B. jumping     
B. invented     
B. carried    
B. later      
B. medal      
B. recognizing        
B. indeed      
B. east        
B. hands       
B. learn from     
B. let           
C. patience          
C. kind-hearted      
C. second            
C. win               
C. set up            
C. slept             
C. stared            
C. over              
C. emphasizing       
C. resting           
C. found             
C. figured           
C. next              
C. prize             
C. discussing        
C. certain           
C. north             
C. sight            
C. keep from         
C. blind             
D. money           
D. hard-working    
D. only          
D. defeat          
D. set out         
D. played          
D. looked        
D. past            
D. complaining     
D. running       
D. realized        
D. depended        
D. further         
D. gold            
D. wondering                        
D. hardly          
D. south           
D. mind            
D. come from       
D. protect       
单项选择题