Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "os"
- "bufio"
- )
- const SEP = '\n'
- func lineChangeFunction(line string) string {
- return line
- }
- func changeFile(inputFilename string, outputFilename string, lineChangeFunction func(string) string) bool {
- inputFile, err := os.Open(inputFilename, os.O_RDONLY, 0)
- if err != nil {
- return false
- }
- defer inputFile.Close()
- outputFile, err := os.Open(outputFilename, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0666)
- if err != nil {
- return false
- }
- defer outputFile.Close()
- in := bufio.NewReader(inputFile)
- for {
- line, err := in.ReadSlice(SEP);
- if err != nil {
- break
- };
- outputFile.WriteString(lineChangeFunction(string(line)))
- }
- return true
- }
- func main() {
- changeFile("input.txt", "output.txt", lineChangeFunction)
- }
Add Comment
Please, Sign In to add comment