golang/goeclipse not writing to a file

blov · · 837 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hey guys, hope you&#39;re having the best monday you could have.</p> <p>I don&#39;t know if this is an import problem, a syntax problem, or a goeclipse problem, but I just cannot write to a file. Here is what I have:</p> <p>package main</p> <p>import ( &#34;os&#34; &#34;io&#34; &#34;fmt&#34; )</p> <p>func main() {</p> <pre><code> filename := &#34;output.txt&#34; file, err := os.Create(filename) if err != nil { fmt.Println(err) } fmt.Println(&#34; Write to file : &#34; + filename) n, err := io.WriteString(file, &#34; Hello World !&#34;) if err != nil { fmt.Println(n, err) } file.Close() </code></pre> <p>}</p> <p>I made this just to figure out how to write to a file. It runs, displays &#34;Write to file: &#34; and shows the file I want to write to, but just simply won&#39;t write to the file.</p> <p>Is there something I&#39;m missing or some kind of thing I have to do in eclipse to get this to work?</p> <p>Thanks again SO much!</p> <p>EDIT: Figured it out thanks to you guys. Issue was a.) I needed to specifically refresh the program and not just clean and save and b.) my directory was really really weird so I needed to change that. Thanks again!</p> <hr/>**评论:**<br/><br/>davecheney: <pre><p>I suspect that the file is being written, but not where you think. Compile and run this program. <a href="http://play.golang.org/p/C-N1zdJalN" rel="nofollow">http://play.golang.org/p/C-N1zdJalN</a></p></pre>Elegantmetal: <pre><p>Awesome this was the issue. It was writing to a VERY weird spot on my 2nd hardrive (some weird folder in my steam directory?) and I was able to change it. Thanks!</p></pre>slmyers: <pre><p>refresh the project and you should see it there.</p></pre>Elegantmetal: <pre><p>By refresh the project do you mean clean and save? Because neither of those worked : /</p></pre>slmyers: <pre><p>I&#39;ve never used the go plugin for eclipse, so this might be wrong, and if so forgive me. </p> <p>Select the project and press f5 and/or right click and look for &#34;Refresh&#34;.</p></pre>Elegantmetal: <pre><p>Ok got it! This solved my main issue of just not working and then davecheney&#39;s solved the other half of my issue. I didn&#39;t think refreshing worked but it ended up writing to a SUPER weird spot on my 2nd hard drive. Thanks everybody!</p></pre>The_Sly_Marbo: <pre><p>Make sure you check the error returned by <code>file.Close()</code>. That may explain what&#39;s going on.</p></pre>Elegantmetal: <pre><p>file.Close() doesn&#39;t seem to be giving me an error when I step over it in debugging. Since I&#39;m new to GDB I could be very incorrect though</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

837 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传