Java语言的输入输出流.ppt

上传人:max****ui 文档编号:6374984 上传时间:2020-02-24 格式:PPT 页数:72 大小:431.55KB
返回 下载 相关 举报
Java语言的输入输出流.ppt_第1页
第1页 / 共72页
Java语言的输入输出流.ppt_第2页
第2页 / 共72页
Java语言的输入输出流.ppt_第3页
第3页 / 共72页
点击查看更多>>
资源描述
第10章Java语言的输入输出与文件处理 本章主要内容 流的概念处理字节流的基本类 InputStream和OutputStream处理字符流的基本类 Reader和Writer标准输入输出文件管理类 File 10 1Java语言的输入输出类库 流 stream 是指计算机各部件之间的数据流动 流是由位或字符组合而成的序列 分类 传输方向 输入流与输出流内容上 字符流和字节流 流用来顺序地读写数据信息 它是一个单向的数据通道 输入流从某个外部的数据源向程序输入数据输出流从程序向外部数据目标输出数据 内存 文件 输入流InputStream 字节流 Reader 字符流 输出流OutputStream 字节流 Writer 字符流 10 2输入输出流类库 Java语言的流类都封装在java io包中 字节流每次读写8位 一个字节 的二进制数 一般为二进制文件 字符流每次读写16位二进制数 并将其作为一个字符而不是二进制为来处理 可以表示任何的文本信息 处理字节流 InputStream和OutputStream处理字符流 Reader和Writer 输入流 InputStream 和输出流 OutputStream 构成字节流的祖先 用来读写如图片 声音之类的二进制文件 这两个类直接继承了Object类 InputStream和OutputStream都是抽象类 InputStream为其他所有字节输入流的超类 而OutputStream为其他所有字节输出流的超类 读取器 Reader 和写出器 Writer 是所有字符流的超类 它们是直接继承Object类的抽象类 用来处理纯文本文件 Reader和Writer可读写16位的字符流 作为抽象类 Reader和Writer必须被子类化才能实现字符流的读写工作 10 2使用InputStream和OutputStream InputStream的方法 publicintread throwsIOException从输入流读取下一个字节 字节值为0 255 如果输入流中不再有数据 返回 1表示输入结束 这是一个阻塞方法 直到有数据可读 或数据流结束 或发生异常时才返回 这是一个抽象方法 需要在具体的子类中加以实现 publicintread byte b throwsIOException从输入流读取一组数据存入缓冲区b中 返回读取字节个数 如果达到数据流结束返回 1 publicintread byte b intoff intlen throwsIOException从输入流读取最多len字节数据存入缓冲区b中 第一个字节存储在b off 随后的按序摆放 返回读取字节个数 如果至数据流结束返回 1 publicintavailable throwsIOException返回输入流中无需阻塞可直接读取字节个数 publicvoidmark intreadlimit throwsIOException在输入流中标记当前位置 以后可调用reset方法返回该位置 这样可以重复读取标记以后的数据 publicvoidreset throwsIOException重置流的读取位置 回到上次调用mark方法标记的位置 publiclongskip longn throwsIOException从输入流中忽略n个字节的数据 返回值为实际忽略的字节个数 publicvoidclose throwsIOException关闭输入流 释放占用的系统资源 流中方法都声明抛出异常 在程序中调用流方法时必须处理异常 否则编译不能通过 在OutputStrem中定义了5个方法 publicabstractvoidwrite intb throwsIOException向输出流写入一个字节 写出字节为整数b的低字节 整数b的3个高字节被忽略 这是一个抽象方法 需要在具体的子类中加以实现 publicvoidwrite byte b throwsIOException把缓冲区b中的全部数据写入输出流 publicvoidwrite byte b intoff intlen throwsIOException把缓冲区b中从b off 开始的len个字节的数据写入输出流 publicvoidflush throwsIOException刷新输出流 强制输出缓冲区的数据立即写出 publicvoidclose throwsIOException关闭输出流 文件输入输出流 文件读写是最常见的I O操作 通过文件流来连接磁盘文件 读写文件内容是一件很轻松的工作 文件输入流 FileInputStream 和文件输出流 FileOutputStream 是抽象类InputStream和OutputStream的具体子类 实现了文件的读写 文件的读写工作包括3个步骤 打开文件输入流或输出流文件读或写操作关闭文件输入流或输出流 FileInputStream实现读文件 调用FileInputStream的构建器可以打开一个文件输入流 FileInputStream的有3个构建器 publicFileInputStream StringfileName throwsFileNotFoundExceptionpublicFileInputStream Filefile throwsFileNotFoundExceptionpublicFileInputStream FileDescriptorfdObj 第一个方法指定文件名 第二个方法指定一个File对象 第三个方法需要指定一个文件描述符对象 FileDescriptor 如果我们试图在一个不存在的文件上打开一个文件输入流 FileInputStream的构建器会抛出异常FileNotFoundException 它是IOException的一个子类 程序应该捕捉这个异常 或者也可以捕捉IOException 实例 读取文件 文件字节输入流 目的 使用FileInputStream类 用FileInputStream的对象把文件读入到内存 importjava io publicclasstest23 publicstaticvoidmain String args FileInputStreamfin null try fin newFileInputStream d a txt intn 0 while n fin read 1 System out print char n byte b newbyte 12 while n fin read b 1 Strings newString b 0 n System out println s catch IOExceptione System out println e getMessage finally try if fin null fin close catch IOExceptione System out println e getMessage importjava io publicclassFileInputS2 publicstaticvoidmain String args throwsIOException FileInputStreamfin newFileInputStream d c txt byte b newbyte fin available intn fin read b Strings newString b 0 n System out print s fin close 和FileInputStream对应的文件输出流FileOutputStream实现了文件输出功能 它的构建器如下 publicFileOutputStream Stringname throwsFileNotFoundExceptionpublicFileOutputStream Stringname booleanappend throwsFileNotFoundExceptionpublicFileOutputStream Filefile throwsFileNotFoundExceptionpublicFileOutputStream FileDescriptorfdObj throwsFileNotFoundException调用第一个构建器时 如果name指定的文件不存在 将创建该文件 并同时建立一个输出流 如果name指定的文件已存在 该文件的内容将会被覆盖 在第二个构建器中 我们可以通过第二个参数append指定是否对已存在的文件进行覆盖 如果append为true 将对文件进行追加写 即新输出的内容将添加到文件尾端 如果append为false 则覆盖原文件 importjava io publicclasstest29 publicstaticvoidmain String args FileOutputStreamfout null try fout newFileOutputStream d a txt Strings hellojava1123 fout write s getBytes catch IOExceptione System out println e getMessage finally try if fout null fout close catch IOExceptione System out println e getMessage mportjava io publicclassFileOUt publicstaticvoidmain String args throwsIOException FileOutputStreamfout newFileOutputStream d 123 txt true Strings1 hellojava Strings2 你好 fout write s1 getBytes fout write s2 getBytes fout close 二进制图形文件的复制 importjava io publicclassapp10 2 publicstaticvoidmain String args FileInputStreamfin null FileOutputStreamfout null try fin newFileInputStream d a1 jpg fout newFileOutputStream d a2 jpg System out println 文件的大小 fin available byte b newbyte fin available fin read b fout write b System out println 文件已被复制并更名 catch FileNotFoundExceptione e printStackTrace catch IOExceptione e printStackTrace finally try if fin null fin close if fout null fout close catch IOExceptione e printStackTrace 习题 通过键盘输入学号 姓名 年龄 利用FileOutputStream类把以上信息写入 student txt 文件中 再复制文件生成 student2 txt 习题 通过键盘输入学号 姓名 年龄 利用DataOutputStream类把以上信息写入 student txt 文件中 再复制文件生成 student2 txt importjava io importjava util publicclassstudata publicstaticvoidmain String args throwsIOException Scannerreader newScanner System in System out println 请输入姓名 学号 年龄 Stringname reader next Stringnum reader next Stringage reader next FileOutputStreamfout newFileOutputStream d student txt fout write name getBytes fout write t fout write num getBytes fout write t fout write age getBytes fout close FileInputStreamfin newFileInputStream d student txt fout newFileOutputStream d student2 txt byte b newbyte fin available fin read b fout write b fin close fout close Runtime getRuntime exec notepad exe d student2 txt 运行可执行文件 过滤输入输出流 Java的流按使用方式可以分为两类 一类是建立了程序和其他数据源或数据目标的数据通道 程序通过这类流可以和流的另一端的数据源或目标进行数据交互 这类数据流称为节点流 nodestream 例如文件输入流FileInputStream和文件输出流FileOutputStream 在它们的另一端是磁盘文件 另一类流 本身并不和具体的数据源和数据目标连接 它们连接在其他输入或输出流上 提供各种数据处理 诸如转换 缓存 加密 压缩等功能 这类流称为过滤器流 filterstream 过滤器输入流从已存在的输入流 比如FileInputStrem 读取数据 对数据进行适当的处理和改变然后再送入程序 过滤器输出流向已存在的输出流 比如FilterOutputSteam 写入数据 在数据抵达底层流之前进行转换处理等工作 特点 过滤输入输出流是建立在基本输入输出流之上 并在输入 输出数据的同时能对所传输的数据做指定类型或格式的转换 即可实现对二进制字节数据的理解和编码的转换 类的层次图 过滤输入流类FilterInputStream和过滤输出流类FilterOutputStream 两者都为抽象类 Java语言中按照基本数据类型进行读写就是数据输入流DataInputStream和数据输出流 DataOutputStream 将基本字节输入输出流 自动转换成按基本数据类型进行读写的过滤流 然后利用流串联的方式 以达到数据转换的目的其分别实现了DataInput和DataOutput两个接口 DataInputStream继承了类FilterInputStream 并且实现了DataInput接口 在类DataInputStream中提供的read方法 booleanreadBoolean 从输入流读取一个字节 如果字节值非0 返回布尔值true 否则返回false bytereadByte 读取一个有符号的字节 字节值范围 128至127 charreadChar 读取一个字符 一个Unicode字符由两个字节构成 doublereadDouble 读取8个字节 并返回一个double型值 floatreadFloat 读取4个字节 并返回一个float型值 intreadInt 读取4个字节 并返回一个int型值 longreadLong 读取8个字节 并返回一个long型值 shortreadShort 读取2个字节 并返回一个short型值 DataOutputStream继承了类FilterOutputStream 并且实现了DataOutput接口 在类DataOutputStream中提供的write方法 voidwriteBoolean booleanv 写出一个boolean值 如果v值为true 则写出1 v值为false 则写出0 voidwriteChar intv 输出一个字符 把v的低16位写到输出流 高16位被丢弃 voidwriteChars Strings 把字符串s写到输出流 字符串s的每个字符对应2个输出字节 voidwriteDouble doublev 输出一个double 对应于8个字节 voidwriteFloat floatv 输出一个float 对应于4个字节 voidwriteInt intv 输出一个int 对应于4个字节 voidwriteLong longv 输出一个long 对应于8个字节 voidwriteShort intv 输出一个short 对应于2个字节 DataInputStream InputStreamin 建立一个新的数据输入流 从指定的输入流in读数据DataOutputStream OutputStreamout 建立一个新的数据输出流 从指定的输入流out读数据 importjava io publicclassapp10 4 publicstaticvoidmain String args FileOutputStreamfout DataOutputStreamdout FileInputStreamfin DataInputStreamdin try dout newDataOutputStrem newFileOutpustream d temp fout newFileOutputStream d temp dout newDataOutputStream fout dout writeInt 10 dout writeLong 12345 dout writeFloat 3 14159267f dout writeDouble 987654321 123 dout writeBoolean true dout writeChars Goodbye dout close catch IOExceptione try fin newFileInputStream d temp din newDataInputStream fin System out println din readInt System out println din readLong System out println din readFloat System out println din readDouble System out println din readBoolean System out println din readChars charch while ch din readChar 0 System out print ch din close catch FileNotFoundExceptione System out println 文件未找到 catch IOExceptione importjava io publicclassStudentData publicstaticvoidmain String args throwsIOException StringfileName d student dat String students ZhangSan LiSi int ages 10 9 DataOutputStreamdout newDataOutputStream newFileOutputStream fileName Tab符用来分隔字段for inti 0 i 2 i dout writeChars students i dout writeChar t dout writeInt ages i dout writeChar t dout close DataInputStreamdin newDataInputStream newFileInputStream fileName for inti 0 i 2 i StringBuffername newStringBuffer charchRead 遇到Tab符结束String字段读取while chRead din readChar t name append chRead intage din readInt din readChar 丢弃分隔符System out println Theageofstudent name is age din close 写出程序的运行结果 写上注释 标准输入输出 Java语言包中有一个类System 这个类没有共有的构建器 因此我们并不能创建这个类的对象实例 不它提供了3个有用的静态类字段 publicfinalstaticInputStreamin publicfinalstaticPrintStreamout publicfinalstaticPrintStreamerr 标准输入输出 System类的这三个静态字段就是系统的标准流 System in表示系统标准输入流 通常环境下标准输入流指向键盘输入 System in read 该方法从键盘缓存区读入一个字节的二进制数据 Charc char System in read System out表示系统标准输出流 通常环境下标准输出流指向屏幕输出 System out print System out println System err表示系统标准错误输出流 通常环境下标准错误输出流也指向屏幕输出 System err print System err println 在程序中 这3个标准流不需我们要显式地打开就可以直接使用 其实它们由系统负责打开 对于标准流如果程序不再使用 也不需要关闭 System out和System err都用于输出 通常情况下System out用于程序输出一般信息 而System err用于输出错误信息和其他需要引起用户立即注意的信息 在系统中 System out具有缓存机制 而System err是没有缓存的 这是两者之间的一个重要区别 System err print e importjava io publicclassapp10 5 publicstaticvoidmain String args try byte b newbyte 128 System out print 请输入字符 intcount System in read b 读取标准输入流System out println 输入的是 for inti 0 i count i System out print b i System out println for inti 0 i count 2 i System out print char b i System out println System out println 输入的字符个数为 count ClassInClass System in getClass ClassOutClass System out getClass System out println in所在的类是 InClass toString System out println out所在的类是 OutClass toString catch IOExceptione e printStackTrace importjava io publicclassEcho publicstaticvoidmain String args int line newint 1024 intcount 0 booleandone false while done try intread System in read if read r elseif read n for inti 0 i count i System out write line i System out write n count 0 elseif read 程序的功能是什么 10 3使用Reader和Writer流类 Reader和Writer类是用来处理 字符流 的 这两个类是抽象类 只是提供了一系列用于字符流处理的接口 不能生成这两个类的实例 只能通过使用由它们派生出来的子类对象来处理字符流 Reader和Writer要解决的 最主要的问题就是国际化 原先的I O类库只支持8位的字节流 因此不可能很好地处理16位的Unicode字符流 Unicode是国际化的字符集 更何况Java内置的char就是16位的Unicode字符 这样加了Reader和Writer之后 所有的I O就都支持Unicode了 Reader 提供的操作 intread throwsIOException 读取一个字符 返回值为读取的字符intread charcbuf throwsIOException 读取一系列字符到数组cbuf 中 返回值为实际读取的字符的数量abstractintread charcbuf intoff intlen throwsIOException 读取len个字符 从数组cbuf 的下标off处开始存放 返回值为实际读取的字符数量 该方法必须由子类实现booleanmarkSupported 判断当前流是否支持做标记voidmark intreadAheadLimit throwsIOException 给当前流作标记 最多支持readAheadLimit个字符的回溯 voidreset throwsIOException 将当前流重置到做标记处abstractvoidclose throwsIOException 关闭 Writer 提供的操作 voidwrite intc throwsIOException 将整型值c的低16位写入输出流voidwrite Stringstr throwsIOException 将字符串str中的字符写入输出流voidwrite charcbuf throwsIOException 将字符数组cbuf 写入输出流abstractvoidwrite charcbuf intoff intlen throwsIOException 将字符数组cbuf 中的从索引为off的位置处开始的len个字符写入输出流voidwrite Stringstr intoff intlen throwsIOException 将字符串str中从索引off开始处的len个字符写入输出流flush 刷空输出流 并输出所有被缓存的字节 close 关闭流 例子 FileRead java InputStreamReader OutputStreamWriter InputStreamReader类是将字节转换为字符的桥梁 且可以在构造器中指定编码的方式 默认使用操作系统的编码方式 常用方法 voidclose 关闭当前流StringgetEncoding 返回此流使用的字符编码的名称intread 读取单个字符intread char cbuf intoffset intlength 将字符读入数组中的某一部分 booleanready 告知是否准备读取此流 OutputStreamWriter是将字符流通过字节流的桥梁 使用指定的charset将写入的字符编码转换为字节输出 可以指定编码方式 默认接受平台的字符集 常用方法voidclose 关闭当前流StringgetEncoding 返回此流使用的字符编码的名称intwrite intc 写入单个字符intwrite char cbuf intoffset intlength 写入cbuf数组中从offset开始长度为length的字符 booleanflush 刷新流的缓冲 InputStreamReader OutputStreamWriter FileReader FileWriter FileReader类继承了InputStreamReader 除了父类的方法外 它还有自己的方法可以直接读取文件内容 构造函数 publicFileReader StringfileName throwsFileNotFoundExceptionpublicFileReader Filefile throwsFileNotFoundExceptionpublicFileReader FileDescriptorfd importjava io publicclassapp10 6 publicstaticvoidmain String args throwsIOException FileReaderfr newFileReader d a txt char c newchar 512 intnum fr read c Strings newString c 0 num System out println 读取的字符个数为 num 其内容如下 System out println s FileWriter类继承了OutputStreamWriter 除了父类的方法外 它还有自己的方法可以直接写字符内容到文件 构造函数publicFileWriter StringfileName throwsIOExceptionpublicFileWriter StringfileName booleanappend throwsIOExceptionpublicFileWriter Filefile throwsIOExceptionpublicFileWriter Filefile booleanappend throwsIOException FileReader FileWriter importjava io publicclassapp10 7 publicstaticvoidmain String args throwsIOException FileWriterfw newFileWriter d c txt char c h e l l o r n Stringstr 欢迎使用Java fw write c fw write str fw close 复制 importjava io publicclasscopyf publicstaticvoidmain String args throwsIOException FileReaderfr newFileReader d c txt FileWriterfw newFileWriter e d txt char c newchar 500 intn fr read c fw write c fr close fw close 10 3 4使用BufferedReader类读取文件 BufferedReader的父类为Reader BufferedReader类用来读取缓冲区里的数据 BufferedReader使用之前 需先创建FileReader类对象 以该对象为参数来创建BufferedReader类的对象 构造方法publicBufferedReader Readerin intsz 创建一个使用指定大小输入缓冲区的缓冲字符输入流 publicBufferedReader Readerin 创建一个使用默认大小输入缓冲区的缓冲字符输入流 BufferedReader类的常用方法 publicintread throwsIOException读取单个字符 publicintread char cbuf throwsIOException将字符读入数组 在某个输入可用 发生I O错误或者已到达流的末尾前 此方法一直阻塞 publicintread char cbuf intoff intlen throwsIOException将字符读入数组的某一部分 publicStringreadLine throwsIOException读取一个文本行 通过下列字符之一即可认为某行已终止 换行 n 回车 r 或回车后直接跟着换行 publiclongskip longn throwsIOException跳过字符 publicvoidclose throwsIOException importjava io publicclassapp3 4 publicstaticvoidmain String args throwsIOException floatnum Stringstr BufferedReaderbuf newBufferedReader newInputStreamReader System in System out print 请输入一个实数 str buf readLine num Float parseFloat str System out println 您输入的数是 num importjava io publicclassapp10 8 publicstaticvoidmain String args StringthisLine intcount 0 try FileReaderfr newFileReader d c txt BufferedReaderbfr newBufferedReader fr while thisLine bfr readLine null count System out println thisLine System out println 共读取了 count 行 bfr close catch IOExceptione System out println 错误 e 使用BufferedWriter类写入文件 BufferedWriter的父类为WriterBufferedWriter类用来将数据写入到缓冲区里首先创建FileWriter对象 再以该对象为参数来创建BufferedWriter类的对象 特点 缓冲区内的数据最后必须用flush 方法将缓冲区清空 也就是将缓冲区中的数据全部写到文件里 构造方法publicBufferedWriter Writerout 创建一个使用默认大小输出缓冲区的缓冲字符输出流 publicBufferedWriter Writerout intsz 创建一个使用给定大小输出缓冲区的新缓冲字符输出流 常用方法publicvoidwrite intc throwsIOException写入单个字符 publicvoidwrite char cbuf intoff intlen throwsIOException写入字符数组的某一部分 publicvoidwrite Strings intoff intlen throwsIOException写入字符串的某一部分 publicvoidnewLine throwsIOException写入一个行分隔符 行分隔符字符串由系统属性line separator定义 并且不一定是单个新行 n 符 publicvoidflush throwsIOException刷新该流的缓冲 publicvoidclose throwsIOException importjava io publicclassBuffedWriter publicstaticvoidmain String args throwsIOException BufferedWriterbfw newBufferedWriter newFileWriter d d txt Strings1 Java 我会好好研究你的 Strings2 学习的乐趣 要自己去发掘 bfw write s1 bfw newLine bfw write s2 bfw flush bfw close importjava io publicclassapp10 9 publicstaticvoidmain String args Stringstr newString try BufferedReaderin newBufferedReader newFileReader d d txt BufferedWriterout newBufferedWriter newFileWriter d d1 txt while str in readLine null System out println str out write str out newLine out flush in close out close catch IOExceptione System out println 错误 e 习题 将一个千千静听中的歌词文件 lrc 作为数据源 按行读入 并将每行歌词前的时间格式字符去掉 如 00 00 62 将歌名和歌词按行写入一个新文件中 文件名和歌词文件名相同 后缀名为txt 10 4文件的处理与随机访问 10 4 1Java语言对文件与文件夹的管理Java io包中定义了File类专门用来管理磁盘文件和文件夹 而不负责数据的输入输出 每个File类对象表示一个磁盘文件或文件夹 其对象属性中包含了文件或文件夹的相关信息 如文件名 长度 和所含文件个数等 调用它的方法可以完成对文件或文件夹的管理操作 File的基本用法 File给出的构造函数publicFile Stringpath 如果path是实际存在的路径 则该File对象表示的是目录如果path是文件名 则该File对象表示的是文件publicFile Stringpath Stringname path是路径名 name是文件名publicFile Filedir Stringname dir是路径名 name是文件名 文件名的处理StringgetName 得到一个文件的名称 不包括路径 StringgetPath 得到一个文件的路径名StringgetAbsolutePath 得到一个文件的绝对路径名StringgetParent 得到一个文件的上一级目录名文件属性测试booleanexists 测试当前File对象所指示的文件是否存在booleancanWrite 测试当前文件是否可写booleancanRead 测试当前文件是否可读booleanisFile 测试当前文件是否是文件 不是目录 booleanisDirectory 测试当前文件是否是目录 文件属性 importjava io publicclassDemo9 publicstaticvoidmain String args Filef1 newFile d a txt 创建File类对象System out println 文件路径 f1 getAbsoluteFile 得到文件的绝对路径System out println 文件长度 f1 length 得到文件的大小 File不负责创建文件 创建文件和文件夹 importjava io publicclassDemo0 publicstaticvoidmain String args Filef newFile d hello txt if f exists try f createNewFile 创建文件 catch IOExceptione e printStackTrace elseSystem out println 有文件 不能创建 importjava io publicclassDemo11 publicstaticvoidmain String args Filef3 newFile d ff if f3 isDirectory System out println 文件夹已存在 elsef3 mkdir 创建文件夹 列出一个文件夹下的所有文件 importjava io publicclassDemo12 publicstaticvoidmain String args Filef newFile d 暴风影音 if f isDirectory Filelists f listFiles 列出文件夹下面的所有子文件for inti 0 i lists length i System out println 文件名 lists i getName importjava io publicclassapp10 10 publicstaticvoidmain String args Stringstr newString try InputStreamReaderisr newInputStreamReader System in BufferedReaderin newBufferedReader isr Stringsdir d cgj 无后缀名 创建的就是文件夹Stringsfile FileFdir1 newFile sdir if Fdir1 exists 10 4 2对文件的随机访问 RandomAccessFile是用来随机访问那些保存数据记录的文件的 而不用按照流的顺序一次读取 构造方法 RandomAccessFile Stringname Stringmode name是文件名mode是打开方式 r 只读 rw 可读写RandomAccessFile Filefile Stringmode file是文件对象mode是打开方式 r 只读 rw 可读写 文件指针的操作longgetFilePointer 用于得到当前的文件指针voidseek longpos 用于移动文件指针到指定的位置intskipBytes intn 使文件指针向前移动指定的n个字节 RandomAccessFile类 importjava io publicclassapp10 11 privatestaticvoiddoAccess try Filefile newFile d c txt RandomAccessFileraf newRandomAccessFile file rw bytech raf readByte System out println readfirstcharacteroffile char ch System out println readfullline raf readLine raf seek file length raf write 0 x0a raf writeBytes Thiswillcompletetheexample raf close catch IOExceptione e printStackTrace publicstaticvoidmain String args throwsIOException doAccess importjava io publicclassapp10 11 publicstaticvoidmain String args throwsIOException StringBufferstfDir newStringBuffer System out println 请输入文件所在的路径 charch while ch char System in read n stfDir append ch Filedir newFile stfDir toString System out println 请输入欲读取的文件名 StringBufferstfFilename newStringBuffer charc while c char System in read n stfFilename append c FilereadFrom newFile dir stfFilename toString if readFrom isFile
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 图纸专区 > 课件教案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!