Java tutorial
//package com.java2s; /* * Copyright (C) 2012 Kazuya (Kaz) Yokoyama <kazuya.yokoyama@gmail.com> * * 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.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import android.os.Environment; public class Main { public static final String extStorageDirectory = Environment.getExternalStorageDirectory().toString() + "/EbentoPics/"; public static final String tmpImageFile = extStorageDirectory + "tmp.jpg"; public static File saveTmpFile(InputStream is) throws Exception { File file = getTmpFile(); OutputStream os = new FileOutputStream(file); byte[] buf = new byte[1024]; int len = 0; while ((len = is.read(buf)) > 0) { os.write(buf, 0, len); } os.flush(); os.close(); return file; } public static File getTmpFile() { File fileDirectory = new File(extStorageDirectory); if (!fileDirectory.exists()) { fileDirectory.mkdir(); } return new File(tmpImageFile); } }