编程开发 > JSP > 文章内容

jsp复习资料(12)

2017-1-18编辑:ljnbset

JSP的输入和输出流
    6.2.1. 字节流
    1.FileInputStream(文件输入流) 和 FileOutputStream(文件输出流)
 FileInputStream(String filepath) throws FileNotFoundException;
 FileInputStream(File fileObj) throws FileNotFoundException;

 FileOutputStream(String filePath);
 FileOutputStream(String filePath, boolean append);
 FileOutputStream(File fileObj);

    2.ByteArrayInputStream(字节数组输入流) 和 ByteArrayOutputStream(字节数组输出流)
 ByteArrayInputStream(byte array[]);
 ByteArrayInputStream(byte array[], int start, int numBytes);

 ByteArrayOutputStream d=new ByteArrayOutputStream();
 d.write(buf)
 ByteArrayOutputStream(int numBytes);
 
    3.BufferedInputStream(缓冲输入流) 和 BufferedOutputStream(缓冲输出流)
 BufferedInputStream(InputStream inputStream);
 BufferedInputStream(InputStream inputStream, int bufSize);

 BufferedOutputStream(OutputStream outputStream);
 BufferedOutputStream(OutputStream outputStream, int bufSize);

 例子:
 String urlString="..."  //表示URL所指定的资源位置的文件
 URL url=new URL(urlString);
 File file=new file(url.getFile());
 String filename=file.getName();
 in = new BufferedInputStream(url.openStream());
 out = new BufferedOutputStream(new FileOutputStream("/"+filename));
 while ((c=in.read())!=-1) out.write(c);

    4.SequenceInputStream(顺序输入流) 和 PushbackInputStream(返回输入流)
 SequenceInputStream(InputStream first, InputStream second);
 SequenceInputStream(Enumeration streamEnum);

 例子:(节选)

 String file1="autoexec.bat";
 String file2="config.sys";
 InputStream in1=new InputStream(new FileInputStream(file1));
 InputStream in2=new InputStream(new FileInputStream(file2));
 SequenceInputStream inseq=SequenceInputStream(in1,in2);
 while ((c=inseq.read())!=-1) System.out.print((char) c);
 


 PushbackInputStream(InputStream inputStream);
 PushbackInputStream(InputStream inputStream, int numBytes);

 PushbackInputStream对象中返回字符流的方法为unread(),有如下几个重载方式:
  void unread(int ch);
  void unread(byte buf[]);
  void unread(byte buf[], int offSet, int numChars);

jsp复习资料(10)

热点推荐

登录注册
触屏版电脑版网站地图