title: golang can't write to text file: the handle is invalid
body: <p>Hello again everybody,</p>
  
  <p>I apologize for asking another question so soon, but it just seems to be one thing after another with Go lately.</p>
  
  <p>I have a working web page scraper (thanks to everybody's help) that grabs all the info I want from this wiki page: <a href="http://monsterhunter.wikia.com/wiki/MH4U:_Item_List" rel="nofollow">http://monsterhunter.wikia.com/wiki/MH4U:_Item_List</a></p>
  
  <p>It then displays everything I want, no hiccups. However, when I go to write to a .txt file I get an error stating: "0 write mh4u.txt: The handle is invalid"</p>
  
  <p>Here is my current code for reference:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "log"
  
      "github.com/PuerkitoBio/goquery"
      "os"
      "io"
  )
  
  func main() {
  
      filename := "mh4u.txt"
      file, err := os.Create(filename)
  
      if err!= nil {
          fmt.Println(err)
      }
      doc, err := goquery.NewDocument("http://www.ign.com/wikis/monster-hunter-4/Items")
      if err != nil {
          log.Fatal(err)
      }
  
      doc.Find("tbody").Each(func(i int, s *goquery.Selection) {
  
          s.Find("td").Each(func(j int, s2 *goquery.Selection) {
  
              if s3 := s2.Find("img"); s3 != nil &amp;&amp; s3.Length() &gt; 0 {
                  return
              }
  
              fmt.Printf(s2.Text())
              n, err := io.WriteString(file, s2.Text())
  
              if err != nil {
                  fmt.Println(n, err) 
              }
          })
  
          file.Close()
      })
  }
  </code></pre>
  
  <p>Testing this code with other web sites leads me to believe that there is maybe some hidden characters that is giving the writer some issues, but that's the only thing I can guess.</p>
  
  <p>Thanks so much for any suggestions/tips/solutions you can offer!</p>