For importing the entire file at once, the only other option that I am aware of is ReadList
. It can be coaxed to returning the entire file as a single string as follows1:
In[1]:= ReadList["ExampleData/source", Record, RecordSeparators -> {}]
Out[1]:= {"f[x] (: function f :)\r\ng[x] (: function g :)\r\n"}
(Note: \r and \n are actually interpreted in the output, but I left them in for readability.) The key is to remove any RecordSeparators
. But, I honestly don't think this saves you anything, and Import[ <file>, "Text"]
is easier to write. Truthfully, I use Read[ <file>, String]
when I have data in a format that isn't covered by the type specifiers used in Read
and ReadList
, and build a custom function around this operation to load in all of the data.
- You can find this in the Reading Textual Data tutorial.