C# File WriteAllLines(String, String[])
Description
File WriteAllLines(String, String[])
Creates a new
file, write the specified string array to the file, and then closes the file.
Syntax
File.WriteAllLines(String, String[])
has the following syntax.
public static void WriteAllLines(
string path,
string[] contents
)
Parameters
File.WriteAllLines(String, String[])
has the following parameters.
path
- The file to write to.contents
- The string array to write to the file.
Returns
File.WriteAllLines(String, String[])
method returns
Example
The following code example demonstrates the use of the WriteAllLines method to write text to a file.
using System;/* www . j a va 2 s .com*/
using System.IO;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
string[] createText = { "Hello", "And", "java2s.com" };
File.WriteAllLines(path, createText);
string[] readText = File.ReadAllLines(path);
foreach (string s in readText)
{
Console.WriteLine(s);
}
}
}