记录自己的java面试题目
2008-03-28 18:55
405 查看
这一段找工作,顺便把面试的题目记录下来。
一.读txt文件
1.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.File;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.FileReader;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class ReadTxt ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public static void main(String[] args) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
File f = new File("D:/sql.txt");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
FileReader fr = new FileReader(f);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char[] temp= new char[(int)f.length()];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fr.read(temp);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
StringBuffer sb = new StringBuffer();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(int i=0;i<temp.length;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sb.append(temp[i]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(sb.toString());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (Exception e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
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();
}
}
}
一.读txt文件
1.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.File;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.FileReader;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class ReadTxt ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public static void main(String[] args) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
File f = new File("D:/sql.txt");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
FileReader fr = new FileReader(f);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char[] temp= new char[(int)f.length()];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fr.read(temp);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
StringBuffer sb = new StringBuffer();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for(int i=0;i<temp.length;i++)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sb.append(temp[i]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(sb.toString());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} catch (Exception e) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.printStackTrace();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
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();
}
}
}
相关文章推荐
- 分类及其内容的一个处理办法
- 今天去面试了
- [summary]缺省路由在各种协议下的发布总结
- CCIE学习(52)—— 默认路由
- 我的2008微软大会体验
- 求职指南qzzn全新上线
- 成功职业经理人应该具有的28个好习惯
- 这里的模板不怎么样!!!
- 第一篇文章
- 程序员的素质 编程修养
- 日记 [2008年03月28日]升级内核后iptables不能用mark
- 几个有关 面试 interview 的链接
- C程序员之歌
- 利用行列转换、外连接和笛卡尔积的一次完美统计
- +13飞魂 (传奇3G)
- 升45武器并不一定大黑铁 自然+13的飞魂 (传奇3G)
- 升流星刀+14方法 (传奇3G)
- 锐起无盘管理器 及相关资源
- IS-IS 知识点 推荐
- Sbo之于中国的使用现状分析 推荐