Does anyone know why Google Go program 1 works, below, and program 2 doesn't? The only difference - I read in the filename from the console in the one that doesn't work but it is a literal in the one that works... I tried typing in the full path for the file, and also "..sample.txt" instead of "sample.txt", but they didn't solve it either.
// program 1 - this works:
  package main import (
      "fmt"
      "os"
      "bufio" )
    Â
    func main() {
      filename := getFilename()
    fmt.Println("opening:",filename)Â
  //    fmt.Println("opening:sample.txt")
      _ , err := os.Open("sample.txt")Â
  //  _ , err := os.Open(filename)
      if err != nil {Â
    panic(err)
      }Â
    }Â
  func getFilename()  string {
    reader := bufio.NewReader(os.Stdin)
    fmt.Print("Enter file name: ")   // type in anything, this file name not used
    filename, _ := reader.ReadString('\n')
    return filename
  }
// program 2 - this doesn't work, gives error shown below:
  package main
  import (
    "fmt"
    "os"
    "bufio"
  )
  Â
  func main()Â
    filename := getFilename()
    fmt.Println("opening:",filename)
  // fmt.Println("opening: sample.txt")
  // _ , err := os.Open("sample.txt")
    _ , err := os.Open(filename)
    if err != nil {
    panic(err)
    }
    }
  func getFilename()  string {
    reader := bufio.NewReader(os.Stdin)
    fmt.Print("Enter file name: ")   // type in "sample.txt" (without the quotes)
    filename, _ := reader.ReadString('\n')
    return filename
  }
Error message, panic invoked -Â
: The filename, directory name, or volume label syntax is incorrect.
goroutine 1 [running]:
main.main()
    C:/installed programs/go/src/testopen2.go:16 +0x158
exit status 2