Read and Write unity txt files, unitytxt read and write
Open the file and write it:
Void CreateOrOPenFile (string path, string name, string info) {// path, file name, and written contentStreamWriter sw;FileInfo fi = new FileInfo (path + "//" + name );Sw = fi. CreateText (); // directly re-write. If you want to Append content to the end of the original file, apply fi. AppendText ()Sw. WriteLine (info );Sw. Close ();Sw. Dispose ();}
Read File Content:
Void LoadFileAndIntialSpeed (string sPath,
1. iterate the row of the fileCopy codeThe Code is as follows:Public static IEnumerable {Using (TextReader reader = File. OpenText (fileName )){String line;If (line = reader. ReadLine ())! = Null){Yield return line;}}}Static void Main (){Foreach (string line in Iterator. ReadLines ("")){Console. WriteLine (line );}}2. Use the iterator and predicate to filter rows in the file.Copy codeThe Code is as follows:Public static IEnumerable {If (source = null
This article provides a detailed analysis of file traversal information using the iterator. For more information, see
This article provides a detailed analysis of file traversal information using the iterator. For more information, see
1. iterate the row of the file
The Code is as follows:
Public static IEnumerable
ReadLines (string fileName)
{
Using (TextReader reader = File. OpenText (fileName ))
{
String line;
If (line = reader
support for Text.
· AppendText: append text to an existing file.· CreateText: Creates or opens a new file for writing text.· OpenText: open an existing text file for reading.
But the above method mainly on the UTF-8 encoding text operations, which is not flexible enough. We recommend that you use the following code to operate the txt file.· Read the txt file. The sample code is as follows:
StreamReader TxtReader = new StreamReader (@ "c: \ tempupload
Example of file operations in ASP. NET (VB)Post: Andy. m Date: popularity: 60
Example of file operations in ASP. NET1. Write filesWritefile. aspxResponse. Write ("writing the content into text file in ASP. NET Dim strwriterobj as streamwriter 'declares a streamwriter objectStrwriterobj = file. createtext ("C:/aspnet.txt") 'creates a text file and assigns it to the streamwriter object.Strwriterobj. writeline ("Welcome to wonderfull world of ASP. NET programming ")'Write content to the fi
files are not prompted for installation. If you find that a library file is not installed, it is possible that the network is bad or the download source is missing. This time the user uses acommand to update download source under”apt-get Update, and then execute the two scripts above. For example, as shown, run again“./install-devel-packages.sh"After that, the prompt does not installLibraries and software, then the installation is complete. reducedGccversionUseUbuntucompilingAndroidneeds to be
as follows:
if (File.exists (@ "C:\tempuploads\newFile.txt"))//Determine if the file exists
{
CopyFile (); Copying files
DeleteFile (); deleting files
MoveFile (); Moving files
}
Else
{
MakeFile (); Generating files
OpenFile (); Open File
Setfile (); Set file properties
}
In addition, the file class provides more support for text literals.
· AppendText: Append text to an existing file
· CreateText: Create or open a new file for writing text
·
Read
You can read data from a file.
ReadWrite
You can read data from one file and write data to the file.
Write
You can write data to the file.
The following code shows how the open () method is used.
FileInfo f = new FileInfo ("F:/myfile.txt");
FileStream s = F.open (Filemode.openorwrite, FileAccess.Read);
using StreamReader class and StreamWriter class to implement file read and write operation
Read and write to
should create a new file.
Open
Specifies that the operating system should open an existing file.
OpenOrCreate
Specifies that the operating system should open the file (if the file exists), otherwise, create a new file.
Truncate
Specifies that the operating system should open an existing file. Once the file is opened, it will be truncated to a size of 0 bytes.
Of course, you can also use (Open, OpenRead, OpenText, Openwrite) to create FileStream
Dim F
(); Moving files}Else{MakeFile (); Generating filesOpenFile (); Open FileSetfile (); Set file properties}In addition, the file class provides more support for text literals.· AppendText: Append text to an existing file· CreateText: Create or open a new file for writing text· OpenText: Open an existing text file for readingBut the above method mainly carries on the operation to the UTF-8 encoded text, thus appears insufficiently nimble. Here the reade
/block block above, which uses the StreamWriter class to write a simple string in a temporary file:
//向临时文件中写入数据 StreamWriter* writer = File::AppendText(fileName);writer->WriteLine("A test sample data");writer->Flush();writer->Close();
The data written can be read through the following StreamReader, where the contents of the entire file are read into a string object:
StreamReader* reader = File::OpenText(fileName);
Finally, after using the tempora
17.3.1 read and write in text mode
The SteamReader and StreamWriter classes provide a way for us to read and write data in text mode. The following example reads the content from a text file and prints it on the screen.
Program Listing 17-5:
Using System;
Using System.IO;
Class Filetest
{public
static void Main ()
{
StreamReader srd;
try{
srd=file.opentext ("C:\\c#\\file1\\file1.txt");
}
Catch
{
Console.WriteLine ("File Open Failed");
return;
}
while (SRD. Peek ()!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.