package cn.file;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class FileTest {
public static void main(String[] args) {
File file = new File("f://word.text");
try {
FileOutputStream out = new FileOutputStream(file);
byte[] buy = "我有一只小毛驴,我从来也不骑。".getBytes();
out.write(buy);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
FileInputStream in = new FileInputStream(file);
byte byt[] = new byte[1024];
int len = in.read(byt);
System.out.println("文本中的信息是:" + new String(byt, 0, len));
in.close();
} catch (Exception e) {
e.printStackTrace();
}
/*
* if(file.exists()){ String name=file.getName(); Long
* length=file.length(); boolean hidden=file.isHidden();
* System.out.println("文件名:"+name); System.out.println("文件内容长:"+length);
* System.out.println("文件是否隐藏:"+hidden); /*file.delete();
* System.out.println("文件已删除");
*
* }else{ try { file.createNewFile(); System.out.println("文件已经创建"); }
* catch (IOException e) { // TODO Auto-generated catch block
* e.printStackTrace(); } }
*/
}/*
* else{ System.out.println("文件不存在"); } }
*/
}