Q:

Read a txt file in Mathematica

Does anyone know how to read a .txt file from Mathematica in lines and save those lines as elements from an array? The file I'm trying to read are names like this:

Brad Pitt
Scarlet Johanson
Woody Allen
etc

I have no experience with Mathematica by the way, thanks.

A:

If you are on Windows and your text file is named C:\dir\names.txt, then you can use
names = StringSplit[Import["C:/dir/names.txt"], "\n"]

to import the file, and then split the resulting string at the end of each new line into an array of strings. Note the different direction of the slashes.
If you aren't on Windows, the command is the same, but the directory won't be prefixed with a drive letter.

