标签:error The character string iter int new stat def
复制文件
func CopyFile(dstFileName string,srcFileName string )(written int64,err error) { srcFile,srcErr := os.Open(srcFileName) if srcErr != nil{ fmt.Println("open src file",srcFileName," error :",srcErr) return -1,srcErr } defer srcFile.Close() reader := bufio.NewReader(srcFile) dstFile,dstErr := os.Open(srcFileName) if dstErr != nil{ fmt.Printf("open dst file %s error,%v\n",dstFileName,err) return -1,dstErr } defer dstFile.Close() writer := bufio.NewWriter(dstFile) return io.Copy(writer,reader) }
统计数字和字母的个数 ,主要用到 strs := []rune(str)
func statistics(fileName string) { file,openErr := os.Open(fileName) if openErr != nil{ fmt.Println(openErr) return } defer file.Close() reader := bufio.NewReader(file) characters := 0 nums := 0 others := 0 for{ str,err := reader.ReadString(‘\n‘) if err == io.EOF{ break } strs := []rune(str) for _,v := range strs{ switch { case v>=‘a‘&&v<=‘z‘: fallthrough//穿透 case v>=‘A‘&&v<=‘Z‘: characters++ case v>=‘0‘&&v<=‘9‘: nums++ default: others++ } } } }
标签:error The character string iter int new stat def
原文地址:https://www.cnblogs.com/superxuezhazha/p/14347168.html