SaveAdd.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:1k
- package com.softeem.webmail.action.receivemail;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- public class SaveAdd {
-
- public static String SaveFile(String filename, InputStream is){
- BufferedReader buff=null;
- BufferedWriter bs=null;
- String url="";
- File file = new File("D/save/"+filename);
- for (int i=0; file.exists(); i++) {
- url=filename+i;
- file = new File(url);
- }
- try {
- OutputStream os=new FileOutputStream(file);
- OutputStreamWriter osw=new OutputStreamWriter(os);
- bs=new BufferedWriter(osw);
- buff=new BufferedReader(new InputStreamReader(is));
- String str="";
- while((str=buff.readLine())!=null){
- bs.write(str);
- bs.flush();
- }
- return url;
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }finally{
- if(buff!=null){
- try {
- buff.close();
- buff=null;
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if(bs!=null){
- try {
- bs.close();
- bs=null;
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return url;
- }
- }