记录自己的java面试题目(1)
这一段找工作,顺便把面试的题目记录下来。
一.读txt文件
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 fis = new FileInputStream("D:sql.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
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();
}
}
}
补充:Jsp教程,Java技巧及代码