相关疑难解决方法(0)

文件mkdirs()方法在android/java中不起作用

我已经把头发拉了一段时间了.以下方法应该下载文件,并将其保存到硬盘驱动器上指定的位置.

private static void saveImage(Context context, boolean backgroundUpdate, URL url, File file) {

    if (!Tools.checkNetworkState(context, backgroundUpdate))
        return;

    // Get the image
    try {
        // Make the file
        file.getParentFile().mkdirs();

        // Set up the connection
        URLConnection uCon = url.openConnection();
        InputStream is = uCon.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);

        // Download the data
        ByteArrayBuffer baf = new ByteArrayBuffer(50);
        int current = 0;
        while ((current = bis.read()) != -1) {
                baf.append((byte) current);
        }

        // Write the bits to the file
        OutputStream os = new …
Run Code Online (Sandbox Code Playgroud)

java android file

11
推荐指数
3
解决办法
9679
查看次数

标签 统计

android ×1

file ×1

java ×1