Skip to content

Instantly share code, notes, and snippets.

@takuya-i
Last active August 29, 2015 14:17
Show Gist options
  • Save takuya-i/b25c3225609d0f15c0ea to your computer and use it in GitHub Desktop.
Save takuya-i/b25c3225609d0f15c0ea to your computer and use it in GitHub Desktop.
android File helper
import android.graphics.Bitmap;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* Created by takuyai on 2015/03/09.
*/
public class FileHelper {
/**
* ビットマップをJPEGファイルとして保存する
* @param bitmap 保存するビットマップ
* @param filePath 保存先ファイルパス(絶対パス)
* @throws IOException 入出力エラー
*/
public static void writeBitmap(Bitmap bitmap, String filePath,int compress) throws IOException {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(filePath);
bitmap.compress(Bitmap.CompressFormat.JPEG,compress , fos);
} catch (IOException e) {
throw e;
} finally {
if (fos != null) {
fos.close();
}
}
}
/**
*
* @param src
* @param dst
* @throws IOException
*/
public static void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment