Record your java interview questions (1)

Source: Internet
Author: User
Tags stringbuffer

When looking for a job in this section, record the interview questions.

1. Read txt files

1.



Import java. io. File;
Import java. io. FileReader;
Public class ReadTxt ...{
Public static void main (String [] args )...{
File f = new File ("D: SQL .txt ");
Try ...{
FileReader fr = new FileReader (f );
Char [] temp = new char [(int) f. length ()];
Fr. read (temp );
StringBuffer sb = new StringBuffer ();
For (int I = 0; I <temp. length; I ++ )...{
Sb. append (temp [I]);
            }
System. out. println (sb. toString ());
} Catch (Exception e )...{
E. printStackTrace ();
        }
    }
}

2.

 



Import java. io. BufferedReader;
Import java. io. FileInputStream;
Import java. io. InputStreamReader;
Public class ReadTxt1 {
Public static void main (String [] args ){
Try {
FileInputStream FCM = new FileInputStream ("D: SQL .txt ");
BufferedReader br = new BufferedReader (new InputStreamReader (FCM ));
String s;
StringBuffer sb = new StringBuffer ();
While (s = br. readLine ())! = Null ){
Sb. append (s + "n ");
            }
System. out. println (sb. toString ());
} Catch (Exception e ){
E. printStackTrace ();
        }
    }
}

 

 



</

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.