小编PAR*_*IYA的帖子

该进程无法访问该文件,因为该文件正在被 Golang 中的另一个进程使用

该进程无法访问该文件...因为它正在被另一个进程使用

我无法使用此代码删除 Zip 文件..

这是可能的?用一段代码提取并删除文件。

代码

package main

import (
    "archive/zip"
    "fmt"
    "io"
    "log"
    "net/http"
    "os"
    "path/filepath"
    "strings"
)

func main() {
    url := "https://230c07c8-77b2-4c0d-9b82-8c6501a5bc45.filesusr.com/archives/b7572a_9ec985e0031042ef912cb40cafbe6376.zip?dn=7.zip"
    out, _ := os.Create("E:\\experi\\1234567890.zip")
    defer out.Close()
    resp, _ := http.Get(url)
    defer resp.Body.Close()
    _, _ = io.Copy(out, resp.Body)
    files, err := Unzip("E:\\experi\\1234567890.zip", "E:\\experi\\1234567890")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Unzipped the following files:\n" + strings.Join(files, "\n"))
}

func Unzip(src string, destination string) ([]string, error) {

    var filenames []string

    r, err := zip.OpenReader(src)

    if err != …
Run Code Online (Sandbox Code Playgroud)

zip go

1
推荐指数
1
解决办法
7336
查看次数

标签 统计

go ×1

zip ×1