找回密码
 立即注册
相关推荐换一批
  1. GB/T 15387.1-1994 术语数据库开发文件编制指南
  2. NY/T 762-2004 蔬菜农业残留检测抽样规范
  3. GB/T 3382-1993 文件传真三类机在电话网中的互通技术条件
  4. SJ 2785-1987 雷达产品随机文件
  5. SJ/T 10151-1991 电子产品设计文件的标准化检查
  6. SJ/T 11156-1998 计算机辅助设计 设计文件档案管理制度
  7. SJ/T 10719-1996 电子设备设计文件编制示例
  8. SJ/T 10631-1995 工艺文件的编号
  9. SJ/T 10375-1993 工艺文件格式的填写
  10. SJ/T 10323-1992 电池产品设计文件的分类编号
  11. GB/T 19097-2003 技术产品文件 生命周期模型及文档分配
  12. GB/T 18253-2000 钢及钢产品 检验文件的类型
  13. FZ/T 90066-1995 纺织机械 产品图样及设计文件的更改
  14. FZ/T 90012-1991 材料在图样及设计文件中的标记方法
  15. FZ/T 91003.8-1993 纺织机械制造工艺管理导则 工艺文件的修改
  16. FZ/T 91003.7-1993 纺织机械制造工艺管理导则 工艺文件标准审查
  17. FZ/T 91001.4-1993 纺织机械制造工艺文件 工艺装备设计图样及文件格式
  18. FZ/T 91001.1-1993 纺织机械制造工艺文件 工艺文件完整性及审批程序
  19. GB/T 13959-1992 文件格式分类与代码编制方法
  20. SJ/T 207.8-2001 设计文件管理制度 第8部分:图样编制
  21. SJ/T 207.7-2001 设计文件管理制度 第7部分:电气简图的编制
  22. SJ/T 207.6-2001 设计文件管理制度 第6部分:项目代号
  23. 中山大学附属小学2016-2017学年度一年级英语上学期期末学业水平测试卷
  24. 2013年新派英语一年级下册期末综合测试卷(含听力材料与参考答案)
theFilethrowsIOExceptio文件 | 企业管理 2022-09-23 213 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
版权声明:自创著作,谢绝转发!否则将追究法律责任。
JAVAIO操作方案
本季知识点
1、File类
2、RandomAccess类
File类
在JAVA中所有的IO操作全面存放在java.io包中。
File是仅有一个与文件自身相关的操作。
在使用File类的结构方法处有必要参加一个完整的途径。
请求一:可以在F盘上建立一个新的文件:demo.txt文件。
publicbooleancreateNewFile()throwsIOException
看下作用:
我们发现系统提示不合法转义字符,在前面学习正则时“\”表明转义,我们需求输入两个“\\”即“f:\\demo.txt”
需求进行try/catch管理
如今发现文件出来了哈~
假如如今再想创建同一个文件,我们会发现显示false,由于文件现已存在,不能再创建同一文件哈~
能否删除去demo.txt的文件呢?
publicbooleandelete()
请求:
假如文件存在则删除去文件,假如文件不存在,则创建文件。
判别文件是不是存在:publicbooleanexists()
注意点:
假如程序按以上格式写的话,则会有一个限制:
·windows:\
·linux:/
File类中提供了几切割符
publicstaticfinalStringseparator
publicStringgetPath()
判别给定的途径是不是是一个目录:publicbooleanisDirectory()
显示f:\demo.txt不是目录哈~
再来看一个:
显示F:\TL-WN310GTL-WN350G是目录哈~
通过这个方法可以判别给定的途径是不是是目录哈~
请求可以列出指定目录下的全面文件。
·回来完整途径:publicStringlist();
·回来全面的File目标:publicFilelistFiles();
1、使用字符串数组操作
可以正常列出F:\资料目录下的文件和目录哈~
2、使用File类目标数组
使用File类可以开出途径哈~
思考题:
不断的判别给定的途径是不是是目录,假如是目录,则持续向下列出,此种标题只能使用递归操作终结。
看下作用:
注意:递归操作可能会致使内存泄露问题~~~
输入输出方法
读写进程
RandomAccessFile
假定一个文件中存放了三组数据:
AA80
BB90
CC99
RandomAccessFile类
publicRandomAccessFile(Filefile,Stringmode)throwsFileNotFoundException
publicRandomAccessFile(Filefile,--gt;File类的实例化目标
Stringmode)--gt;模式
throwsFileNotFoundException
模式如今主要用两种:
·r:只读
·w:只写
·rw:读写--gt;假如没有文件,写时,会自动创建。
publicfinalvoidwriteBytes(Strings)throwsIOException
publicfinalvoidwriteInt(intv)throwsIOException
看下作用:
如今我们可以注入数据了,下面我们将其读出来哈~
实际上读的时候只能按byte读出,byte只能一个一个的往外读。
假如读完第一自己的数据,则此时指针在第二自己之前,假如持续往下读则会读取第二自己的数据,我们测试一下哈~~
假如我们想不读取第一自己的数据,直接读取第二自己的数据,看下面哈~~
publicfinalbytereadByte()throwsIOException
publicintskipBytes(intn)throwsIOException
publicvoidseek(longpos)throwsIOException
看下作用,直接读取第二自己数据了哈~
假如要读取第三自己数据即是跳过16个字节哈~raf1.skipBytes(16);
如今我们是一直往下读哈,我们要使指针往回读取数据呢?
看下作用:
尽管此类可以比较灵敏的实现读写操作,但是也是有故障的,由于有必要认识的其跳的长度。
真实开发中使用的数据读取类:InputStream、OutputStream、Reader、Writer,下季再会分晓哈~~~~
##############################################################

(Copyright statement: self-created works, please do not forward! Otherwise, legal responsibility will be pursued.
JAVAIO operation plan
Knowledge points this season
1. File class
2. RandomAccess class
File class
All IO operations in JAVA are fully stored in the java.io package.
File is only one operation related to the file itself.
It is necessary to take a complete approach in using the structured methods of the File class.
Request 1: You can create a new file on the F drive: the demo.txt file.
publicbooleancreateNewFile() throwsIOException
Take a look at the effect:
We found that the system prompts illegal escape characters. When learning regular expressions, "\" indicates escape. We need to enter two "\\", namely "f:\\demo.txt"
Require try/catch management
Now I found the file came out~
If we want to create the same file now, we will find that false is displayed. Since the file already exists, we cannot create the same file again~
Can I delete the demo.txt file?
publicbooleandelete()
ask:
If the file exists, delete the file, if the file does not exist, create the file.
Determine whether the file exists: publicbooleanexists()
be careful:
If the program is written in the above format, there will be a limitation:
·windows:\
·linux:/
Several delimiters are provided in the File class
publicstaticfinalStringseparator
publicStringgetPath()
Determine if the given path is a directory: publicbooleanisDirectory()
It shows that f:\demo.txt is not a directory~
One more look:
It shows that F:\TL-WN310GTL-WN350G is the directory ha~
This method can be used to determine whether a given path is a directory or not~
The request can list comprehensive files in the specified directory.
·Return the full way: publicStringlist();
Return the full File object: publicFilelistFiles();
1. Use string array operations
The files and directories in the F:\data directory can be listed normally~
2. Use the File class target array
Using the File class can open a way~
Thinking questions:
Constantly determine whether the given path is a directory or not, and if it is a directory, it will continue to be listed downwards. This kind of title can only be terminated by recursive operation.
Take a look at the effect:
Note: recursive operations may cause memory leaks~~~
I/O method
read and write process
RandomAccessFile
Suppose three sets of data are stored in a file:
AA80
BB90
CC99
RandomAccessFile class
publicRandomAccessFile(Filefile,Stringmode) throwsFileNotFoundException
publicRandomAccessFile(Filefile,--gt; the instantiation target of the File class
Stringmode)--gt; mode
throwsFileNotFoundException
There are two main modes in use today:
r: read only
w: write only
rw: read and write --gt; if there is no file, it will be created automatically when it is written.
publicfinalvoidwriteBytes(Strings) throwsIOException
publicfinalvoidwriteInt(intv) throwsIOException
Take a look at the effect:
Now we can inject data, let's read it out below~
In fact, when reading, it can only be read by byte, and the byte can only be read out one by one.
If you finish reading the data of the first self, then the pointer is before the second self. If you continue to read down, the data of the second self will be read. Let's test it~~
If we don't want to read the data of the first self, but directly read the data of the second self, see below~~
publicfinalbytereadByte() throwsIOException
publicintskipBytes(intn) throwsIOException
publicvoidseek(longpos) throwsIOException
Look at the effect, directly read the second self data ha~
If you want to read the third self data, you will skip 16 bytes~raf1.skipBytes(16);
Now we have been reading down, do we want to make the pointer read data back?
Take a look at the effect:
Although this class can implement read and write operations more sensitively, it is also faulty, because it is necessary to know the length of its hops.
Data reading classes used in real development: InputStream, OutputStream, Reader, Writer, we will find out next season~~~~
################################################## ############)

[下载]10472346012.rar




上一篇:EJB3实例教材
下一篇:[零基础学JAVA]Java SE应用部分-28.Java IO操作(02)