Importing and Exporting Data

Importing and exporting tabular data.

This exports an array of numbers to the file out.dat:

Export["out.dat",{{5.7,4.3},{-1.2,7.8}}]

Here are the contents of the file out.dat:

FilePrint["out.dat"]

This imports the contents of out.dat as a table of data:

Import["out.dat","Table"]

(RefLink[Import, paclet:ref/Import])["file","Table"] will handle many kinds of tabular data, automatically deducing the details of the format whenever possible. (RefLink[Export, paclet:ref/Export])["file",list,"Table"] writes out data separated by tabs, with numbers given in C or Fortran-like form, as in 2.3E5 and so on.

Importing and exporting general data.

Some common formats for tabular data.

(RefLink[Import, paclet:ref/Import]) and (RefLink[Export, paclet:ref/Export]) can handle not only tabular data, but also data corresponding to graphics, sounds, expressions and even whole documents. (RefLink[Import, paclet:ref/Import]) and (RefLink[Export, paclet:ref/Export]) can often deduce the appropriate format for data simply by looking at the extension of the file name for the file in which the data is being stored. "Exporting Graphics and Sounds" and "Importing and Exporting Files" discuss in more detail how (RefLink[Import, paclet:ref/Import]) and (RefLink[Export, paclet:ref/Export]) work. Note that you can also use (RefLink[Import, paclet:ref/Import]) and (RefLink[Export, paclet:ref/Export]) to manipulate raw files of binary data.

This imports a graphic in JPEG format:

Import["ExampleData/turtle.jpg"]

Finding the complete list of supported import and export formats.