我如何输入我的文件?

How do I input My FIle?

我仔细研究并找到了一个复制文件的功能,我唯一的问题是我不知道我在哪里插入我的目录(我正在移动 "/data/data/com.android.providers.contacts/databases/contacts2.db""/sdcard/tpzb/"

非常感谢您的帮助。我只需要有人把 "FILE TO COPY DIR""OUTPUT DIR" 放在它去的地方。我知道这是一个愚蠢的问题,但我看到了很多其他类似的功能,我想一旦我看到一个,我就可以自己弄明白而无需询问。 :)

private void moveFile(String inputPath, String inputFile, String outputPath) {

    InputStream in = null;
    OutputStream out = null;
    try {

        //create output directory if it doesn't exist
        File dir = new File (outputPath); 
        if (!dir.exists())
        {
            dir.mkdirs();
        }


        in = new FileInputStream(inputPath + inputFile);        
        out = new FileOutputStream(outputPath + inputFile);

        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
        in.close();
        in = null;

            // write the output file
            out.flush();
        out.close();
        out = null;

        // delete the original file
        new File(inputPath + inputFile).delete();  


    } 

使用这个code复制文件

此外,不要忘记在 AndroidManifest.xml 文件中添加以下权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

用法

copyFile("/data/data/com.android.providers.contacts/databases/contacts2.db", Environment.getExternalStorageDirectory().toString() + "/tpzb/");