Java 文件操作

Java 文件操作

//

String path=";

File f=new File(path);//(path,path1)  init

boolean b=f.exists();//exist?true\fal

boolean c=f.creatNewFile();//create  success?tur\fal

boolean d=f.mkdir();//createdir  f.mkdirs("a//b//c");

boolean e=f.delete();//delete

Sting h=f.getName();//getAbsolutePath();

boolean i=f.renameTo(f2);//renameTo(File)

boolean j=f.canRead();//can?tur\fal

boolean k=f.isDirectory();//yes?tur\fal  isFile() isHidden()

File[] files=f.listFiles();

for(File f1:files)

{

System.out.println(f1.girName());

}

Java 流

文件流

字节

FileOutputStream out=new FileOutputStream("");//未找到创建

String str="";

byte[] buffer=str.getBytes();

out.write(buffer);

out.close();

FileInputStream in=new FileImageInputStream("");// 未找到异常

int a;

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

{

System.out.println((char)a);

}

in.close();

字符

FileWriter out=new FileWriter("");

Sting str="";

out.write(str);

out.close();

FileReader in=new FileReader("");

int  c;

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

{

System.out.println((char)c);

}



缓冲流

字节

BufferOutputStream bos=new BufferedOutputStream(out);

bos.write(byte[]);

bos.close();

BufferedInputStream bis=new BuffereInputStream(in);

bis.read(byte[]);

bis.close();

字符

BufferdWriter bw=new BufferWriter(out);

bw.Write("");

bw.close();

BufferedReader br=new BufferedReader(in);

while((s=br.readLine())!=null)

System.out.println(s);

br.close();

转换流

new OutputStreamwriter(new FileOutputStream(""));//字节->字符

new InputStreamReader(System.in);

打印流

PrintStream ps=new PrintStream(in);

System.setOut(ps);//输出重定向

System.out.println();

数据流

DataOutputStream;

DataInputStream;

对象流

ObjectInputStream;

ObjectOutputStream;

implements Serializable接口

translent 忽略序列化

你可能感兴趣的:(Java 文件操作)