开发者

Copying png file from a folder to another

I have a PNG file in a folder, I want to copy this file to another folder. Is there a easy way to do this ?

Example:

//Creating PNG 

              File file = new File(Environment.getExternalStorageDirectory()
                + File.separator+"/S_Temp/temp_"+formattedDate+".png");

       开发者_C百科       FileOutputStream  out = new FileOutputStream(file);
              view.mBitmap.compress(Bitmap.CompressFormat.PNG,100, out);

So, I have the PNG in the SD card in the folder "S_Temp", now I want to copy this file to a new folder in the SD card itself, say "S".

Thanks in advance

Happy Coding


private static void copyfile(String srFile, String dtFile){
try{
  File f1 = new File(srFile);
  File f2 = new File(dtFile);
  InputStream in = new FileInputStream(f1);

  //For Append the file.
  //OutputStream out = new FileOutputStream(f2,true);

  //For Overwrite the file.
  OutputStream out = new FileOutputStream(f2);

  byte[] buf = new byte[1024];
  int len;
  while ((len = in.read(buf)) > 0){
    out.write(buf, 0, len);
  }
  in.close();
  out.close();
  System.out.println("File copied.");
}
catch(FileNotFoundException ex){
  System.out.println(ex.getMessage() + " in the specified directory.");
  System.exit(0);
}
catch(IOException e){
  System.out.println(e.getMessage());      
}
}

try this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜