-1

アプリケーションパス(/ data / data / package name)からsdcard.forにpdfファイルをコピーしたいのですが、

try {
        source = new FileInputStream(sourceFile).getChannel();
        destination = new FileOutputStream(destFile).getChannel();
        destination.transferFrom(source, 0, source.size());
    }
    finally {
        if(source != null) {
            source.close();
        }
        if(destination != null) {
            destination.close();
        }
    }

動作していません。ヘルプをご覧ください。

4

1 に答える 1

1

ファイルをコピーするためのサンプルコードは次のとおりです

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

//                  If you want to 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());

        }
        catch(IOException e){
            System.out.println(e.getMessage());         
        }
    }
于 2012-06-29T15:22:01.783 に答える