本帖最后由 新晋猿工 于 2016-7-25 10:24 编辑
- package cn.itcast.javatest;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class FileCopyDemo {
- public static void main(String[] args) throws IOException {
- File file = new File("test.txt");
- FileOutputStream fos = new FileOutputStream(file, true);
- if (!file.exists()) {
- file.createNewFile();
- }
- fos.write("HelloWorld".getBytes());
- fos.close();
- FileInputStream fis = new FileInputStream(file);
- int by = 0;
- while((by = fis.read())!=-1){
- System.out.print((char)by);
- }
- fis.close();
- }
- }
复制代码 |