您的位置:首页 > 编程语言 > Java开发

Java中File类使用

2013-11-05 21:05 330 查看
ioStream.java

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class iostream_sample {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File f = new File("hello.test");
if(!f.exists() ){
f.createNewFile();
System.out.println("creat file success!");
}
FileOutputStream outStream = new FileOutputStream(f);
outStream.write("hello world".getBytes());
outStream.close();

FileInputStream inStream = new FileInputStream(f);
byte [] buf = new byte[1024];
int len = inStream.read(buf);
System.out.println(new String(buf, 0, len));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java File