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 ();
}
}
}
</