inputStream--->
inputstreamReader,fileInputStream,bufferedReader,dataInputStream,objectInputStream,Reader
outputStream-->
outputStreamReader,fileOutputStream,bufferedWriter,dataoutputStream,objectOutputStream,writer
文件操作--->File file=new File(String pathName);---直接通过路径创建
file.separator()-----"/"==="\\","."当前目录".."上一级目录 file.getObsolutePath()--->绝对路径file.isFile()是否为文件 file.isDirectory()是否为目录
File afile=new File(String parent,String child);---由父路径和子路径共同创建文件
file.createNewFile()---创建新文件;file.mkdir()---最后级目录;file.mkdirs()--多级目录;
file.exists()---文件是否存在;file().getName()--获取文件名;file.getPath()--获取路径;file.length()---文件大小(字节)
file.list()----列出文件列表;file.listFiles()---列出所有子文件夹和子文件
文件上传-->servletFileupload
fileUploadServlet核心接口form(enctype=multipart/form-data)DiskFileItemFactory();FileItemFactory();servletFileUpload();setHeaderEncoding();setSizeMax();setFileSizeMax();parseRequest(httpServletRequest);isMultipartContent(httpservletRequest);FileItem();getFieldName();getString();getContentType();getInputStream();getName();writer();delete();
setRepository()------>临时存储路径
core-code--->
DiskFileItemFactory factory=new DiskFileItemFactory();
ServletFileUpload upload=new ServletFileUpload(factory);
upload.setSizeMax(30*1024*1024);
upload.setFileSizeMax(10*1024*1024);
if(upload.isMultipartContent(request)){
List<FileItem> list=upload.parseRequest(request);
for(FileItem item:list){
if(item.isFormField()){
String fieldName=item.getFieldName();
String value=item.getString("UTF-8");
System.out.println("fieldName"+fieldName+",value="+value());
}else{
String name=item.getName();
String uuid=UUID.randomUUID().toString();
name=uuid+name;
String uploadPath=getServletContext().getRealpath("/upload");
File file=new File(uploadPath,name);
item.write(file);
item.delete();
}
}
}