1 / 16

第六章 JSP 文件操作 ( 续 )

西南科技大学网络教育系列课程 动态网页设计( JSP ). 第六章 JSP 文件操作 ( 续 ). 字符流. 在实际应用中,存在一类文本数据,它们可能采用各种不同的字符编码方式 ( 字符集 ) ,可能是单字节字符,也可能是多字节字符,这就需要借助于字符流来处理文本类信息。读取器 (Reader) 和写出器 (Writer) 是所有字符流的超类,它们是直接继承 Object 类的抽象类。. 字符输入流的类层次结构. 字符输入流. 常用方法:. public abstract void close() throws IOException.

graceland
Télécharger la présentation

第六章 JSP 文件操作 ( 续 )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 西南科技大学网络教育系列课程 动态网页设计(JSP) 第六章 JSP文件操作(续)

  2. 字符流 • 在实际应用中,存在一类文本数据,它们可能采用各种不同的字符编码方式(字符集),可能是单字节字符,也可能是多字节字符,这就需要借助于字符流来处理文本类信息。读取器(Reader)和写出器(Writer)是所有字符流的超类,它们是直接继承Object类的抽象类。 字符输入流的类层次结构

  3. 字符输入流 • 常用方法: public abstract void close() throws IOException public int read() throws IOException public int read(char[]cbuf) throws IOException public abstract int read(char[]cbuf, intoff, intlen) throws IOException public long skip(longn) throws IOException

  4. 字符输入流 FileReader类 public FileReader(StringfileName) throws FileNotFoundException public FileReader(Filefile) throws FileNotFoundException 实例:用字符输入流读取文件 fileReaderExample1.jsp

  5. 字符流 字符输出流的类层次结构

  6. 字符输出流 • Writer类常用方法 public void write(String str) throws IOException public void write(char[] cbuf) throws IOException public abstract void write(char[] cbuf, int off, int len)throws IOException public abstract void close() throws IOException public abstract void flush() throws IOException

  7. 字符输出流 • FileWriter类 public FileWriter(String fileName) throws IOException public FileWriter(File file) throws IOException public FileWriter(StringfileName, booleanappend) throws IOException FileWriter类 public BufferedWriter(Writerout) public BufferedWriter(Writerout, intsz) 实例:用字符输出流写文件 filewriterExample1.jsp

  8. 6.4随机读写文件 • RandomAccessFile和FileInputStream和FileOutputStream不同,它既可以读取一个文件,也可以写入一个文件。 RandomAccessFile类具有如下的构建器: public RandomAccessFile(String name, String mode) throws FileNotFoundException public RandomAccessFile(File file, String mode) throws FileNotFoundException 其中第一个参数使用文件名或File对象指定一个文件。第二个参数mode指定文件的打开方式,mode为“r”时,指定文件按只读方式打开;mode为“rw”时,文件按只读写方式打开。

  9. RandomAccessFile的方法 • public void close() throws IOException public long getFilePointer() throws IOException public long length() throws IOException public int read() throws IOException public final void readFully(byte[]b) throws IOException public final StringreadLine() throws IOException

  10. RandomAccessFile的方法 public void seek(longpos) throws IOException public void setLength(longnewLength) throws IOException public void write(byte[]b) throws IOException public final void writeByte(intv) throws IOException 程序实例:随机读取文件程序示例 RandomAccessFileExample1.jsp 程序实例:故事接龙 InputStory.jsp

  11. 文件的上传与下载 用普通方法实现文件上传 实例:文件上传 UploadFileExample1.jsp AccepteUploadFile.jsp 实例:文件下载DownFileExample2.jsp

  12. 用组件实现文件的上传与下载 jspSmartUpload 组件安装 相关类的介绍 File类 savaAs()方法 savaAs(String dstFileName) savaAs(String dstFileName,int savaAsOption) SAVEAS_PHYSICAL SAVEAS_VIRTUAL

  13. jspSmartUpload相关类的介绍 File类 isMissing() getFieldName() getFileName() Files类 getCount() getSize() getCollection()

  14. jspSmartUpload相关类的介绍 request类 smartUpload类 Initialize() upload() save() getRequest() getFiles() setAllowedFileList(String allowedFilesList)

  15. jspSmartUpload相关类的介绍 smartUpload类 setDeniedFilesList() setMaxFileSize() setTotalMaxFileSize() downloadFile() 实例:用jspSmartUpload组件实现文件上传 uploadFile.html do_upload.jsp 实例:应用jspSmartUpload组件进行较复杂的表单处理 uploadFile2.html do_upload2.jsp

  16. 文件的分页显示 实例:分页读取文件内容 fenye.jsp 小结

More Related