String byte[] stream File之间的相互转换
2014-04-20 16:10
507 查看
public static InputStream stringTOInputStream(ByteString webpage) throws Exception { ByteArrayInputStream is = new ByteArrayInputStream( webpage.toByteArray()); return is; } public static void inputstreamtofile(InputStream ins, File file) { try { OutputStream os = new FileOutputStream(file); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { os.write(buffer, 0, bytesRead); } os.close(); ins.close(); } catch (Exception e) { e.printStackTrace(); android.util.Log.d("PADATEST", "inputstreamtofile =" + e.getMessage()); } } public void saveUrlImg(String url, File file) { ByteArrayOutputStream os = null; byte[] result = null; try { InputStream is = new java.net.URL(url).openStream(); inputstreamtofile(is, file); is.close(); } catch (Exception e) { e.printStackTrace(); android.util.Log.d("PADATEST", "saveUrlImg =" + e.getMessage()); } } public static File getFilePath(String filePath, String fileName) { File file = null; makeRootDirectory(filePath); try { file = new File(filePath + fileName); } catch (Exception e) { e.printStackTrace(); } return file; } public static void makeRootDirectory(String filePath) { android.util.Log.d("PADATEST", "filePath =" + filePath); File file = null; try { file = new File(filePath); if (!file.exists()) { file.mkdirs(); } } catch (Exception e) { } }
相关文章推荐
- C#图像处理:Stream 与 byte[] 相互转换,byte[]与string,Stream 与 File 相互转换等
- c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换
- c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换
- c#byte[]和string,Image;Stream 和 文件之间的转换
- stream 、 string 、byte[] 间的相互转换 扩展方法
- Bitmap与byte、file、Drawable之间的相互转换
- JAVA中String和byte[]和InputStream之间的相互转换
- C# 字符串string和内存流MemoryStream及比特数组byte[]之间相互转换
- Android学习笔记-InputStream与String,Byte之间的相互转换
- 如何将一个string类型转成byte[]之间相互转换
- C# Stream、string 和 byte[] 之间的转换
- Java String 和 byte[] 之间的相互转换
- String和byte[]之间的相互转换
- byte数组和String之间的相互转换代码
- 15、关于String,File,InputStream之间的相互转换
- C# 字符串string和内存流MemoryStream及比特数组byte[]之间相互转换
- stream 、 string 、byte[] 间的相互转换 扩展方法
- Stream 和 byte[] 之间的转换
- String, InputStream, byte之间转换
- c# Bitmap byte[] Stream 文件相互转换