using System; using System.IO; using System.Text;class Test { public static void Main() { int n; //你要写入的次数 string temp="a"; //你要写入的字符串 StringBuilder sb = new StringBuilder(); string path = @"c:\temp\MyTest.txt"; if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter sw = File.CreateText(path)) { for (int i=1;i<=n;i++) { sb = sb.Append(temp); } sw.WriteLine(sb.ToString()); } } // Open the file to read from. using (StreamReader sr = File.OpenText(path)) { string s = ""; while ((s = sr.ReadLine()) != null) { Console.WriteLine(s); } } } }
using System.IO;
using System.Text;class Test
{
public static void Main()
{
int n; //你要写入的次数
string temp="a"; //你要写入的字符串
StringBuilder sb = new StringBuilder(); string path = @"c:\temp\MyTest.txt";
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
for (int i=1;i<=n;i++)
{
sb = sb.Append(temp);
}
sw.WriteLine(sb.ToString());
}
} // Open the file to read from.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
}
[C#]
public string PadLeft(
int totalWidth,
char paddingChar
);
[C#]
public string PadRight(
int totalWidth,
char paddingChar
);