public void copyFile(String mainPath,String extPath){
String abPath=Environment.getExternalStorageDirectory().getPath();
File mainFile=new File(mainPath);
File extFile=new File(extPath);
String fileName=new File(extPath).getName();
FileInputStream inputStream=null;
try{
inputStream=new FileInputStream(mainFile);
}catch(FileNotFoundException e){
e.printStackTrace();
}
FileOutputStream outputStream=null;
try{
outputStream=new FileOutputStream(extFile);
}catch(FileNotFoundException e){
e.printStackTrace();
}
FileChannel fcin=inputStream.getChannel();
FileChannel fcout=outputStream.getChannel();
long size = 0;
try {
size = fcin.size();
} catch (IOException e) {
e.printStackTrace();
}
try {
fcin.transferTo(0, size, fcout);
} catch (IOException e) {
e.printStackTrace();
}
try {
fcout.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
fcin.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
이 코드로 제폰에서 파일을 복사하고있는데요 기본저장소에 복사하는건 되는데 외부저장소(sd카드)에 복사하면 에러가뜰까요...?
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:29828 flg=0x43 }} to activity {com.example.joseph.gellery_image/com.example.joseph.gellery_image.EditActivity_1}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.nio.channels.FileChannel java.io.FileOutputStream.getChannel()' on a null object reference
위처럼 에러가뜨네요...