一个简单的java输出程序_一个简单有趣的java文件输出

import java.io.*;

class Test {

public static void main(String[] args) {

try {

FileInputStream in

= new FileInputStream("foo.txt");

FileOutputStream out

= new FileOutputStream("bar.txt");

int c;

while ((c = in.read()) != -1)

out.write(c);

in.close();

out.close();

} catch (IOException e) {

System.err.println(e);

System.exit(1);

}

}

}

--------------------------------------

很简单的java文件输出

中间的int c 是什么呢?

打出来System.out.println(c);

foo.txt的内容

aa

bb

cc

打印的结果

97

97

13

10

98

98

13

10

99

99

13

10

这些数字是什么呢?

这些数字是10进制ASCII码

------另外一个例子------------

public class ReadWriteFile {

public static void main(String[] args) {

try {

File read = new File("c:\\1.txt");

File write = new File("c:\\2.txt");

BufferedReader br = new BufferedReader(new FileReader(read));

BufferedWriter bw = new BufferedWriter(new FileWriter(write));

String temp = null;

temp = br.readLine();

while (temp != null) {

// 写文件

bw.write(temp + "\r\n"); // 只适用Windows系统

// 继续读文件

temp = br.readLine();

}

bw.close();

br.close();

} catch (FileNotFoundException e) { // 文件未找到

System.out.println(e);

} catch (IOException e) {

System.out.println(e);

}

}

}

-----------附录---------

以下是常用的ASCII码对照表:

十进制十六进制 字符   99TAB(制表符) 10A换行 13D 回车 3220空格 3321! 3422" 3523# 3624$ 3725% 3826& 3927' 4028( 4129) 422A* 432B+ 442C, 452D- 462E. 472F/ 48300 49311 50322 51333 52344 53355 54366 55377 56388 57399 583A: 593B; 603C< 613D= 623E> 633F? 6440@ 6541A 6642B 6743C 6844D 6945E 7046F 7147G 7248H 7349I 744AJ 754BK 764CL 774DM 784EN 794FO 8050P 8151Q 8252R 8353S 8454T 8555U 8656V 8757W 8858X 8959Y 905AZ

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值