For example, the file myFile.cs might not be a C# source file. As a result, while TXT files created in Windows will display correctly in OS X, TXT files created in OS X will be missing all the line breaks when. Check the path and the spelling of the file name.ĭo not rely on the name of a file to determine the contents of the file. However, there is one little but quite significant difference between plain text files made in the two OSs: In Windows, line breaks are \r. Click Utilities, then Terminal in the icon grid. The application is in the folder that opens.
![how to read a .txt file on mac how to read a .txt file on mac](https://imgssl.constantcontact.com/kb/ThirdParty/excel-2013-import-text-file-overlay-selected-file-and-import-button-step3.png)
How to read a .txt file on mac how to#
If you are not using the text files from How to write to a text file, replace the argument to ReadAllText and ReadAllLines with the appropriate path and file name on your computer. You can find this app in the Applications folder in Finder or by using Spotlight. Keep the console window open in debug mode.Ĭonsole.WriteLine("Press any key to exit.") Ĭopy the code and paste it into a C# console application. Use a tab to indent each line of the file. While Mac OS Xs built-in TextEdit can certainly get the job done, there are text editors that are far more robust. String lines = Display the file contents by using a foreach loop. Read each line of the file into a string array. String text = Display the file contents to the console. file name to substitute text files of your own.
![how to read a .txt file on mac how to read a .txt file on mac](https://cdn-60c35131c1ac185aa47dd21e.closte.com//wp-content/uploads/2018/12/textedit-preferences.png)
The files used in this example are created in the topic The files that are used in this example are created in the topic How to write to a text file.