forked from wufenggirl/LeetCode-in-Golang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
44 lines (38 loc) · 656 Bytes
/
util.go
File metadata and controls
44 lines (38 loc) · 656 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"io/ioutil"
"log"
"os"
"os/exec"
)
func max(a, b int) int {
if a > b {
return a
}
return b
}
// read 负责读取文件
// 这是一个通用的方法
func read(path string) []byte {
file, err := os.Open(path)
if err != nil {
panic(err)
}
defer file.Close()
data, err := ioutil.ReadAll(file)
return data
}
func write(path, content string) {
err := ioutil.WriteFile(path, []byte(content), 0755)
if err != nil {
log.Fatal(err)
}
}
// 利用 VSCode 打开文件
func vscodeOpen(filename string) {
cmd := exec.Command("code", "-r", filename)
_, err := cmd.Output()
if err != nil {
panic(err.Error())
}
}