The issue you're encountering is that your input is likely not UTF-8 (which is what bufio and most of the Go language/stdlib expect). Instead, your input probably uses some extended-ASCII codepage, which is why the unaccented characters are passing through cleanly (UTF-8 is also a superset of 7-bit ASCII), but that the 'Ñ' is not passed through intact.
In this situation, the bit-representation of the accented character is not valid UTF-8, so the unicode replacement character (U+FFFD) is being produced. You've got a few options:
- Convert your input files to UTF-8 before passing them to Go. There are many utilities that can do this, and editors often have this feature.
- Try using golang.org/x/text/encoding/charmap together with NewReader from golang.org/x/text/transform to transform your input to UTF-8. Pass the resulting Reader to bufio.NewScanner
- Change the line in the loop to
os.Stdout.Write(scanner.Bytes()); fmt.Println();This might avoid the bytes being interpreted as UTF-8 beyond newline splitting. Writing the bytes directly to
os.Stdoutwill further avoid any (mis)interpretation of the contents.