Java FileOutputStream Write saveFile(InputStream is, File file)

Here you can find the source of saveFile(InputStream is, File file)

Description

save File

License

Apache License

Declaration

private static void saveFile(InputStream is, File file) throws IOException, FileNotFoundException 

Method Source Code

//package com.java2s;
/**/*from  w  ww  .java  2  s .c  o  m*/
 *  Copyright 2009, 2011 Welocalize, Inc. 
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  
 *  You may obtain a copy of the License at 
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  
 */

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    private static void saveFile(InputStream is, File file) throws IOException, FileNotFoundException {
        file.getParentFile().mkdirs();
        file.createNewFile();
        FileOutputStream outstream = new FileOutputStream(file);
        int c;
        while ((c = is.read()) != -1) {
            outstream.write(c);
        }
        outstream.close();
        is.close();
        if (file.length() == 0) {
            file.delete();
        }
    }
}

Related

  1. saveFile(final byte[] bytes, final File target)
  2. saveFile(final File file, final byte[] dataToSave)
  3. saveFile(final File file, final String contents, final String encoding)
  4. saveFile(final InputStream in, final String path, final String fileName)
  5. saveFile(final String filename, final String s1, final String textOut, final String s3)
  6. saveFile(InputStream is, String destDir, String fileName)
  7. savefile(InputStream source, String destination)
  8. saveFile(InputStream uploadedInputStream, String serverLocation)
  9. saveFile(String content, String path)