JAVA简明教程_chap11.txt_第1页
JAVA简明教程_chap11.txt_第2页
JAVA简明教程_chap11.txt_第3页
JAVA简明教程_chap11.txt_第4页
JAVA简明教程_chap11.txt_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

file javafilefilefile嵥io 11.1 file4 static string pathseparator /“;“ dospath static char pathseparatorchar /; static string separator /“ windows static char separatorchar / file3 public java.io.file(string pathname) public java.io.file(string parent,string filename) public java.io.file(file parent,string filename) pathnamefilenamefile 1 file / import java.io.*; class filecons public static void main(string args) try file f1 = new file(“c:“); file f2 = new file(“c:“,“windows“); file f3 = new file(f1,“sss.txt“); file f4 = new file(“filecons.java“); file f5 = new file(“asdf+?12/“); system.out.println(“path of f1 is “ + f2.getpath(); if (f3.exists() system.out.println(f3 +“ exists“); else f3.createnewfile(); system.out.println(“f3 was created!“); catch(java.io.ioexception e) e.printstacktrace(); / path of f1 is c:windows f3 was created! path of f4 is c:javacodezcbch11filecons.java path of f1 is c:windows c:sss.txt exists path of f4 is c:javacodezcbch11filecons.java f4f54 11.2 嵥 嵥listfile string list() string list(filenamefilter filter) 2 嵥 / import java.io.*; public class dirlist public static void main(string args) file dir = new file(“); string files = null; if(dir.exists() files = dir.list(); for (int i=0; i 2filter()filenamefilter / / dirlist2.java import java.io.*; public class dirlist2 public static filenamefilter filter(final string afn) / creation of anonymous inner class: return new filenamefilter() string fn = afn; public boolean accept(file dir, string n) / strip path information: string f = new file(n).getname(); return f.indexof(fn) != -1; ; / end of anonymous inner class public static void main(string args) try file path = new file(“.“); string list; if(args.length = 0) list = path.list(); else list = path.list(filter(args0); for(int i = 0; i “); system.exit(0); file f = new file(args0); if(!f.exists() system.out.println(f.tostring() +“ not exists!“); else if(f.isdirectory() system.out.println(“this is a directory“); else system.out.println(“this is a file“); printproperty(f); / 磺 java file1properties file1properties.java this is a file name: file1properties.java path: file1properties.java parent: null can read? true can write? true is hidden? false is readonly? true length: 1304 iast modified: wed jul 30 16:49:24 cst 2003 is absolute? false absolutepath: c:javacodezcbch11file1properties.java 11.5 java 2 filecreatetempfile file createtempfile(string prefix, string suffix) file createtempfile(string prefix, string suffix, file directory) prefixsuffix磬f.createtempfile(“$“,“$“)“$42154$“filewindowsc:windowstempdeleteonexit() 8 / import java.io.*; public class tempfiledemo public static void main(string args) file tempdir = new file(“c:temp“); file tmp1 = null; file tmp2 = null; try if (!tempdir.exists() tempdir.mkdir(); tmp1 = file.createtempfile(“$“, “ttt“, tempdir); tmp2 = file.createtempfile( “ttt“,“$“, tempdir); /tmp1.deleteonexit

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论