c#-使用文件打开软件并从中读取
我想通过打开一个具有特定扩展名的文件(这里没有问题)直接启动我的软件,但我想知道如何直接读取该文件的内容 我在网上查了一下,但没发现什么有用的东西 谢谢这是您需要的,您应该提供一个序列化程序来从该文件中获取特定数据c#-使用文件打开软件并从中读取,c#,readfile,C#,Readfile,我想通过打开一个具有特定扩展名的文件(这里没有问题)直接启动我的软件,但我想知道如何直接读取该文件的内容 我在网上查了一下,但没发现什么有用的东西 谢谢这是您需要的,您应该提供一个序列化程序来从该文件中获取特定数据 但是你想从那个文件中读什么呢?如果它是一个可执行文件,我认为您不想读取该文件,或者?尝试使用file类,尤其是 MSDN使用示例 using System; using System.IO; using System.Text; class Test { public st
但是你想从那个文件中读什么呢?如果它是一个可执行文件,我认为您不想读取该文件,或者?尝试使用
file
类,尤其是
MSDN使用示例
using System;
using System.IO;
using System.Text;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
// This text is added only once to the file.
if (!File.Exists(path))
{
// Create a file to write to.
string createText = "Hello and Welcome" + Environment.NewLine;
File.WriteAllText(path, createText);
}
// This text is always added, making the file longer over time
// if it is not deleted.
string appendText = "This is extra text" + Environment.NewLine;
File.AppendAllText(path, appendText);
// Open the file to read from.
string readText = File.ReadAllText(path);
Console.WriteLine(readText);
}
}
为了从命令行读取文件名(双击时调用)
另请参见。如何打开该文件?请您分别显示代码行好吗?可能重复:@MichalKlouda:Opening已经开始工作了,根据OP的说法。很难说,我的理解是,OP将扩展与他打开的应用程序相关联,但它不处理参数。@MichalKlouda:True,这也是可能的。。。因此,我要求查看相应的代码。事实上,我想双击一个文件,它会启动软件,所以我不知道任何路径,读取该文件不是一个问题是完美的,这样一个白痴,它肯定像linux一样工作。。。谢谢你,我习惯于在linux上工作,而不是在windows上工作,所以有时候我不会把两者联系起来。
using System;
using System.IO;
using System.Text;
class Test
{
public static void Main(string[] args)
{
Console.Writeline("I bet your filename is: {0}", args[0]);
}
}