all: replace io/ioutil with io and os package

For #45557

Change-Id: I12784eeadcbb467819307a6ec8008f940f215065
GitHub-Last-Rev: 4cc337ea4a4a7c59d5d9226911ecf0d4a71aa44c
GitHub-Pull-Request: golang/perf#5
Reviewed-on: https://go-review.googlesource.com/c/perf/+/430796
Run-TryBot: Jenny Rakoczy <jenny@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
diff --git a/analysis/app/compare.go b/analysis/app/compare.go
index 497df49..c686cc7 100644
--- a/analysis/app/compare.go
+++ b/analysis/app/compare.go
@@ -9,8 +9,8 @@
 	"errors"
 	"fmt"
 	"html/template"
-	"io/ioutil"
 	"net/http"
+	"os"
 	"path/filepath"
 	"sort"
 	"strconv"
@@ -163,7 +163,7 @@
 
 	q := r.Form.Get("q")
 
-	tmpl, err := ioutil.ReadFile(filepath.Join(a.BaseDir, "template/compare.html"))
+	tmpl, err := os.ReadFile(filepath.Join(a.BaseDir, "template/compare.html"))
 	if err != nil {
 		http.Error(w, err.Error(), 500)
 		return
diff --git a/analysis/app/index.go b/analysis/app/index.go
index d69aa90..5ae641a 100644
--- a/analysis/app/index.go
+++ b/analysis/app/index.go
@@ -6,8 +6,8 @@
 
 import (
 	"html/template"
-	"io/ioutil"
 	"net/http"
+	"os"
 	"path/filepath"
 
 	"golang.org/x/perf/storage"
@@ -17,7 +17,7 @@
 func (a *App) index(w http.ResponseWriter, r *http.Request) {
 	ctx := requestContext(r)
 
-	tmpl, err := ioutil.ReadFile(filepath.Join(a.BaseDir, "template/index.html"))
+	tmpl, err := os.ReadFile(filepath.Join(a.BaseDir, "template/index.html"))
 	if err != nil {
 		http.Error(w, err.Error(), 500)
 		return
diff --git a/analysis/app/trend.go b/analysis/app/trend.go
index 312fff6..213e282 100644
--- a/analysis/app/trend.go
+++ b/analysis/app/trend.go
@@ -11,9 +11,9 @@
 	"encoding/json"
 	"fmt"
 	"html/template"
-	"io/ioutil"
 	"math"
 	"net/http"
+	"os"
 	"path/filepath"
 	"sort"
 	"strconv"
@@ -39,7 +39,7 @@
 
 	q := r.Form.Get("q")
 
-	tmpl, err := ioutil.ReadFile(filepath.Join(a.BaseDir, "template/trend.html"))
+	tmpl, err := os.ReadFile(filepath.Join(a.BaseDir, "template/trend.html"))
 	if err != nil {
 		http.Error(w, err.Error(), 500)
 		return
diff --git a/benchfmt/reader_test.go b/benchfmt/reader_test.go
index 9636dff..b1bad87 100644
--- a/benchfmt/reader_test.go
+++ b/benchfmt/reader_test.go
@@ -8,7 +8,6 @@
 	"bytes"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 	"path/filepath"
 	"reflect"
@@ -283,7 +282,7 @@
 
 func BenchmarkReader(b *testing.B) {
 	path := "testdata/bent"
-	fileInfos, err := ioutil.ReadDir(path)
+	fileInfos, err := os.ReadDir(path)
 	if err != nil {
 		b.Fatal("reading test data directory: ", err)
 	}
diff --git a/benchstat/sort_test.go b/benchstat/sort_test.go
index 878d3f4..9fdb363 100644
--- a/benchstat/sort_test.go
+++ b/benchstat/sort_test.go
@@ -5,8 +5,8 @@
 package benchstat
 
 import (
-	"io/ioutil"
 	"log"
+	"os"
 	"runtime"
 	"sort"
 	"testing"
@@ -76,11 +76,11 @@
 		t.Skipf("files not available on GOOS=%s", runtime.GOOS)
 	}
 	sampleCompareCollection := Collection{Alpha: 0.05, AddGeoMean: false, DeltaTest: UTest}
-	file1Data, err := ioutil.ReadFile(file1)
+	file1Data, err := os.ReadFile(file1)
 	if err != nil {
 		log.Fatal(err)
 	}
-	file2Data, err := ioutil.ReadFile(file2)
+	file2Data, err := os.ReadFile(file2)
 	if err != nil {
 		log.Fatal(err)
 	}
@@ -101,7 +101,7 @@
 		t.Skipf("files not available on GOOS=%s", runtime.GOOS)
 	}
 	sampleCollection := Collection{Alpha: 0.05, AddGeoMean: false, DeltaTest: UTest}
-	file1Data, err1 := ioutil.ReadFile(file1)
+	file1Data, err1 := os.ReadFile(file1)
 	if err1 != nil {
 		log.Fatal(err1)
 	}
diff --git a/cmd/benchsave/benchsave.go b/cmd/benchsave/benchsave.go
index 51f32c4..5a41f1d 100644
--- a/cmd/benchsave/benchsave.go
+++ b/cmd/benchsave/benchsave.go
@@ -21,7 +21,6 @@
 	"flag"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"log"
 	"mime"
 	"net/http"
@@ -86,7 +85,7 @@
 	var headerData []byte
 	if *header != "" {
 		var err error
-		headerData, err = ioutil.ReadFile(*header)
+		headerData, err = os.ReadFile(*header)
 		if err != nil {
 			log.Fatal(err)
 		}
diff --git a/cmd/benchsave/oauth.go b/cmd/benchsave/oauth.go
index 1905d66..a5193d9 100644
--- a/cmd/benchsave/oauth.go
+++ b/cmd/benchsave/oauth.go
@@ -8,7 +8,6 @@
 	"context"
 	"encoding/json"
 	"fmt"
-	"io/ioutil"
 	"log"
 	"os"
 	"os/user"
@@ -105,7 +104,7 @@
 // readToken obtains a token from the filesystem.
 // If there is no valid token found, it returns a nil token and a reason.
 func readToken() (*oauth2.Token, error) {
-	data, err := ioutil.ReadFile(tokenFilePath())
+	data, err := os.ReadFile(tokenFilePath())
 	if err != nil {
 		return nil, err
 	}
@@ -126,5 +125,5 @@
 	if err != nil {
 		return err
 	}
-	return ioutil.WriteFile(p, data, 0600)
+	return os.WriteFile(p, data, 0600)
 }
diff --git a/cmd/benchseries/main_test.go b/cmd/benchseries/main_test.go
index 529a51a..0319404 100644
--- a/cmd/benchseries/main_test.go
+++ b/cmd/benchseries/main_test.go
@@ -9,7 +9,6 @@
 	"encoding/json"
 	"flag"
 	"io"
-	"io/ioutil"
 	"os"
 	"path/filepath"
 
@@ -72,7 +71,7 @@
 	bo := writeJsonBytes(oddComparisons)
 
 	eref := filepath.Join("testdata", evenReference)
-	re, err := ioutil.ReadFile(eref)
+	re, err := os.ReadFile(eref)
 	if err != nil {
 		t.Log(err)
 		t.Fail()
@@ -80,7 +79,7 @@
 	compareBytes(t, be, re, "calculated even bytes", eref)
 
 	oref := filepath.Join("testdata", oddReference)
-	ro, err := ioutil.ReadFile(oref)
+	ro, err := os.ReadFile(oref)
 	if err != nil {
 		t.Log(err)
 		t.Fail()
diff --git a/cmd/benchstat/main_test.go b/cmd/benchstat/main_test.go
index ed8aba9..50f54dc 100644
--- a/cmd/benchstat/main_test.go
+++ b/cmd/benchstat/main_test.go
@@ -7,7 +7,7 @@
 import (
 	"bytes"
 	"flag"
-	"io/ioutil"
+	"io"
 	"os"
 	"os/exec"
 	"path/filepath"
@@ -69,7 +69,7 @@
 		}
 		c := make(chan []byte)
 		go func() {
-			data, err := ioutil.ReadAll(r)
+			data, err := io.ReadAll(r)
 			if err != nil {
 				t.Error(err)
 			}
@@ -94,7 +94,7 @@
 		exit = os.Exit
 
 		data := <-c
-		golden, err := ioutil.ReadFile(name + ".golden")
+		golden, err := os.ReadFile(name + ".golden")
 		if err != nil {
 			t.Fatal(err)
 		}
@@ -115,7 +115,7 @@
 }
 
 func writeTemp(t *testing.T, data []byte) string {
-	f, err := ioutil.TempFile("", "benchstat_test")
+	f, err := os.CreateTemp("", "benchstat_test")
 	if err != nil {
 		t.Fatal(err)
 	}
diff --git a/internal/diff/diff.go b/internal/diff/diff.go
index bc6b9a2..a66d33d 100644
--- a/internal/diff/diff.go
+++ b/internal/diff/diff.go
@@ -6,14 +6,13 @@
 
 import (
 	"fmt"
-	"io/ioutil"
 	"os"
 	"os/exec"
 	"runtime"
 )
 
 func writeTempFile(dir, prefix string, data []byte) (string, error) {
-	file, err := ioutil.TempFile(dir, prefix)
+	file, err := os.CreateTemp(dir, prefix)
 	if err != nil {
 		return "", err
 	}
diff --git a/storage/app/upload_test.go b/storage/app/upload_test.go
index 237bb61..d06643b 100644
--- a/storage/app/upload_test.go
+++ b/storage/app/upload_test.go
@@ -11,7 +11,6 @@
 	"encoding/json"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"mime/multipart"
 	"net/http"
 	"net/http/httptest"
@@ -83,7 +82,7 @@
 	if resp.StatusCode != 200 {
 		t.Fatalf("post /upload: %v", resp.Status)
 	}
-	body, err := ioutil.ReadAll(resp.Body)
+	body, err := io.ReadAll(resp.Body)
 	if err != nil {
 		t.Fatalf("reading /upload response: %v", err)
 	}
diff --git a/storage/client.go b/storage/client.go
index eee6439..12d6ce2 100644
--- a/storage/client.go
+++ b/storage/client.go
@@ -11,7 +11,6 @@
 	"encoding/json"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"mime/multipart"
 	"net/http"
 	"net/url"
@@ -54,7 +53,7 @@
 	}
 	if resp.StatusCode != 200 {
 		defer resp.Body.Close()
-		body, err := ioutil.ReadAll(resp.Body)
+		body, err := io.ReadAll(resp.Body)
 		if err != nil {
 			return &Query{err: err}
 		}
@@ -148,7 +147,7 @@
 		return &UploadList{err: err}
 	}
 	if resp.StatusCode != 200 {
-		body, err := ioutil.ReadAll(resp.Body)
+		body, err := io.ReadAll(resp.Body)
 		if err != nil {
 			return &UploadList{err: err}
 		}
@@ -240,7 +239,7 @@
 		}
 		defer resp.Body.Close()
 		if resp.StatusCode != 200 {
-			body, _ := ioutil.ReadAll(resp.Body)
+			body, _ := io.ReadAll(resp.Body)
 			errCh <- fmt.Errorf("upload failed: %v\n%s", resp.Status, body)
 			return
 		}
diff --git a/storage/client_test.go b/storage/client_test.go
index 6e5b87e..d740444 100644
--- a/storage/client_test.go
+++ b/storage/client_test.go
@@ -8,7 +8,6 @@
 	"bytes"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"net/http"
 	"net/http/httptest"
 	"reflect"
@@ -119,7 +118,7 @@
 			if have, want := p.FileName(), fmt.Sprintf("want%d.txt", i); have != want {
 				t.Errorf("file name = %q, want %q", have, want)
 			}
-			content, _ := ioutil.ReadAll(p)
+			content, _ := io.ReadAll(p)
 			if have, want := string(content), "content"; have != want {
 				t.Errorf("unexpected content %q, want %q", have, want)
 			}
@@ -177,7 +176,7 @@
 			if have, want := p.FileName(), fmt.Sprintf("want%d.txt", i); have != want {
 				t.Errorf("file name = %q, want %q", have, want)
 			}
-			content, _ := ioutil.ReadAll(p)
+			content, _ := io.ReadAll(p)
 			if have, want := string(content), "content"; have != want {
 				t.Errorf("unexpected content %q, want %q", have, want)
 			}
diff --git a/storage/fs/local/local_test.go b/storage/fs/local/local_test.go
index b34ab23..0697b99 100644
--- a/storage/fs/local/local_test.go
+++ b/storage/fs/local/local_test.go
@@ -6,7 +6,6 @@
 
 import (
 	"context"
-	"io/ioutil"
 	"os"
 	"path/filepath"
 	"testing"
@@ -17,7 +16,7 @@
 func TestNewWriter(t *testing.T) {
 	ctx := context.Background()
 
-	dir, err := ioutil.TempDir("", "local_test")
+	dir, err := os.MkdirTemp("", "local_test")
 	if err != nil {
 		t.Fatalf("TempDir = %v", err)
 	}
@@ -40,7 +39,7 @@
 		t.Fatalf("Close = %v", err)
 	}
 
-	have, err := ioutil.ReadFile(filepath.Join(dir, "dir/file"))
+	have, err := os.ReadFile(filepath.Join(dir, "dir/file"))
 	if err != nil {
 		t.Fatalf("ReadFile = %v", err)
 	}