本文整理汇总了C#中System.IO.StreamWriter.write方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamWriter.write方法的具体用法?C# System.IO.StreamWriter.write怎么用?C# System.IO.StreamWriter.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamWriter
的用法示例。
在下文中一共展示了System.IO.StreamWriter.write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testBaseDir
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testBaseDir() throws Exception
public virtual void testBaseDir()
{
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File super = createTempDir("fsResourceLoaderBase").getAbsoluteFile();
File @base = createTempDir("fsResourceLoaderBase").AbsoluteFile;
try
{
@base.mkdirs();
Writer os = new System.IO.StreamWriter(new System.IO.FileStream(@base, "template.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write), Encoding.UTF8);
try
{
os.write("foobar\n");
}
finally
{
IOUtils.closeWhileHandlingException(os);
}
ResourceLoader rl = new FilesystemResourceLoader(@base);
assertEquals("foobar", WordlistLoader.getLines(rl.openResource("template.txt"), StandardCharsets.UTF_8).get(0));
// Same with full path name:
string fullPath = (new File(@base, "template.txt")).ToString();
assertEquals("foobar", WordlistLoader.getLines(rl.openResource(fullPath), StandardCharsets.UTF_8).get(0));
assertClasspathDelegation(rl);
assertNotFound(rl);
// now use RL without base dir:
rl = new FilesystemResourceLoader();
assertEquals("foobar", WordlistLoader.getLines(rl.openResource((new File(@base, "template.txt")).ToString()), StandardCharsets.UTF_8).get(0));
assertClasspathDelegation(rl);
assertNotFound(rl);
}
finally
{
TestUtil.rm(@base);
}
}
示例2: runTest
/// <summary> Runs the test.
/// </summary>
public virtual void runTest()
{
try {
assureResultsDirectoryExists(RESULTS_DIR);
Configuration c = new Configuration(TEST_CONFIG);
System.IO.StreamWriter result = new System.IO.StreamWriter(getFileName(RESULTS_DIR, "output", "res"));
message(result, "Testing order of keys ...");
showIterator(result, c.Keys);
message(result, "Testing retrieval of CSV values ...");
showVector(result, c.getVector("resource.loader"));
message(result, "Testing subset(prefix).getKeys() ...");
Configuration subset = c.subset("file.resource.loader");
showIterator(result, subset.Keys);
message(result, "Testing getVector(prefix) ...");
showVector(result, subset.getVector("path"));
message(result, "Testing getString(key) ...");
result.write(c.getString("config.string.value"));
result.Write("\n\n");
message(result, "Testing getBoolean(key) ...");
//UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Boolean.toString' may return a different value. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1043"'
result.Write(new Boolean(c.getBoolean("config.boolean.value")).ToString());
result.Write("\n\n");
message(result, "Testing getByte(key) ...");
result.Write(new Byte(c.getByte("config.byte.value")).ToString());
result.Write("\n\n");
message(result, "Testing getShort(key) ...");
result.Write(new Short(c.getShort("config.short.value")).ToString());
result.Write("\n\n");
message(result, "Testing getInt(key) ...");
result.Write(new Integer(c.getInt("config.int.value")).ToString());
result.Write("\n\n");
message(result, "Testing getLong(key) ...");
result.Write(new Long(c.getLong("config.long.value")).ToString());
result.Write("\n\n");
message(result, "Testing getFloat(key) ...");
result.Write(new Float(c.getFloat("config.float.value")).ToString());
result.Write("\n\n");
message(result, "Testing getDouble(key) ...");
result.Write(new Double(c.getDouble("config.double.value")).ToString());
result.Write("\n\n");
message(result, "Testing escaped-comma scalar...");
result.write(c.getString("escape.comma1"));
result.Write("\n\n");
message(result, "Testing escaped-comma vector...");
showVector(result, c.getVector("escape.comma2"));
result.Write("\n\n");
result.Flush();
result.Close();
if (!isMatch(RESULTS_DIR, COMPARE_DIR, "output", "res", "cmp")) {
fail("Output incorrect.");
}
} catch (System.Exception e) {
System.Console.Error.WriteLine("Cannot setup ConfigurationTestCase!");
SupportClass.WriteStackTrace(e, Console.Error);
System.Environment.Exit(1);
}
}