




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 仓储物流中心租赁押金合同与货物配送服务协议
- 婚姻关系解除后赡养责任起始时间协议书
- 离婚财产分割协议中车辆贷款权益确认及归属协议
- 工业用地租赁合同续签及土地使用条件调整协议
- 离婚后子女抚养权变更与财产分割执行协议书
- 软件开发居间合同签订策略六大要素保障利益
- 2025年凉山中考历史真题及答案
- 2025-2030动力总成电动化转型节奏与传统车企战略调整分析报告
- 2025-2030功能性饮料消费行为与品牌差异化战略研究报告
- 2025-2030功能性运动内衣市场需求细分与产品创新研究报告
- 《商务英语视听说(3)》教学大纲
- 洱海保护课件
- 2024呼和浩特粮油收储有限公司招聘19名工作人员笔试备考试题及答案解析
- 乡村医生法律法规培训
- (北师大版2024)七年级数学上学期期中测试卷
- 义务教育法主题班会课件
- 全国计算机等级考试一级历年考试真题试题库(含答案)
- 《系统工程与决策分析》全册配套课件
- 数据驱动的教育决策
- 租房转让协议书
- 译林版七年级上学期英语第一次月考试卷(含答案解析)
评论
0/150
提交评论