mashen08.09整理今日所学
来源:互联网 发布:银行程序员怎么样 编辑:程序博客网 时间:2024/05/02 23:21
1.将123.txt与456.txt这2个文件合并到第三个文件789.txt中
import java.io.*;
public class IO_Test {
public static void main(String[] args) throws IOException {
InputStream is = new FileInputStream("e:/123.txt");
byte[] b = new byte[200];
int length = 0;
String s = null;
//文件123的内容
StringBuffer sb1 = new StringBuffer();
//读取123文件内容
while (-1 != (length = is.read(b))) {
s = new String(b, 0, length);
sb1.append(s);
}
//读取文件456内容
InputStream ins = new FileInputStream("e:/456.txt");
byte[] by = new byte[200];
int len = 0;
//文件456内容
StringBuffer sb2 = new StringBuffer();
while (-1 != (len = ins.read(by))) {
String st = new String(by, 0, len);
sb2.append(st);
}
//创建文件789.txt
File file1 = new File("e:/789.txt");
if (!file1.exists()) {
file1.createNewFile();
}
sb1.append(sb2);
String context = sb1.toString();
OutputStream ops = new FileOutputStream(file1);
//写入合并后内容
ops.write(context.getBytes());
ops.flush();
ops.close();
ins.close();
}
}
2.将99乘法表放入a.txt中
public class TestTable {
public static void main(String[] args) throws IOException {
/*
99乘法表放入文件a.txt中
*/
String s = null;
StringBuffer sb = new StringBuffer();
for(int x =1; x< 10; x++){
for(int y = 1; y<= x; y++){
s = new String(x+"*"+y+"="+x*y+"\t");
sb.append(s);
}
sb.append("\n");
}
String context = sb.toString();
File fl = new File("e:\\a.txt");
if(!fl.exists()){
fl.createNewFile();
}
OutputStream os = new FileOutputStream(fl);
os.write(context.getBytes());
}
}
- mashen08.09整理今日所学
- 今日所学
- 今日所学
- 今日所学(9.4)
- [今日所学]2016.2.13
- [今日所学] 第二天
- [今日所学]第三天
- 今日所学所感
- python-今日所学
- 今日所学-------二级联动菜单
- 今日之所学····
- 2007年5月15日 今日之所学
- [今日所学] 第5天 LeetCode Power of Three
- 从今天开始,整理每日所学
- mashen08.09——————补08.08作业
- 所学所学所学TSSSSSSSSSSSSSSSSS
- 今日整理PDF电子书资料
- 今日遇到的问题整理
- Using Elasticsearch in Symfony2 Project
- 【面试积累】牛人的面试技巧分享
- js注意事项14
- Android开发案例发送短信调用SmsManager 03
- oracle数据库操作——SQL Plus和PL/SQL
- mashen08.09整理今日所学
- epoll机制代码核对
- 协作为何如此的重要?
- 1003: 相邻数对问题
- Matlab_learning_0(linspace,std,size,ones,errorbar)
- 做计划的功能和作用
- USACO 母亲的牛奶 Mother's Milk
- 文章标题
- C++实现根据类名动态生成类对象