0

I am trying to import a txt file read the first line and get that printed to the screen to just test it. But it won't work and says that there is no file in the directory, but my .jl file and .txt file are in the same folder and I have check 10 times over that they are spelt the same. This was what I tried.

f =open("alphabet.txt");

a=readline(f)

println(a)

close(f)

Sorry for the basic nature of the question, but I have checked all the Julia documentation, but can't find an answer

Fengyang Wang
  • 11,901
  • 2
  • 38
  • 67
Jacques
  • 1
  • 1

1 Answers1

4

It seems that you are not in the directory that you think you are in.

You can use

pwd() 

to see which directory Julia is working in, and

readdir()

to get the list of files in that directory.

David P. Sanders
  • 5,210
  • 1
  • 23
  • 23
  • Thanks so much I had spend ages thinking you had to save the .txt file with the .jl files. How would I change the location that Julia looks for the files? – Jacques Nov 17 '15 at 15:17
  • You can do, for example, `f = open("data/alphabet.txt")` (using Linux/Mac syntax) to open the text file in the `data` subdirectory. If you need something more complicated, try the `joinpath` function, that allows you to string together parts of the absolute address of the file in the filesystem. – David P. Sanders Nov 17 '15 at 15:30