Issue with on windows


I am using the following code to read a file on windows:

xmlFile, err := os.Open("…/…/projectinfo.xml")

This works fine as long as the folder name does not have a space in it. How do I need to change the code so it can handle a folder name with spaces?

import "io/ioutil"
import "fmt"

func main() {
txt, _ := ioutil.ReadFile("C:/Program Files/Windows NT/api_to_be_dev.txt")

This worked for me.

Is it a typing error with three dots … It should be just two to go to parent folder.

Hi @johandalabacka,

For some reason when I copy/pasted my code the editor added the extra dots. Not sure why.

Hi @akhilravuri,

I won’t be able to use file open because I am using io.Multiwriter. Here is another line that I use at the beginning of my code:

file, err := os.Create("../../logs/errorlog.txt")

	if err != nil {

		log.Fatal("Cannot create file", err)
	defer file.Close()

	mw := io.MultiWriter(os.Stdout, file)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.