using System.IO;
//定义变量
private Stream myStream;
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialogA = new OpenFileDialog();
openFileDialogA.InitialDirectory = "D:\\CCD-Program";
//加入想要文件格式
openFileDialogA.Filter = "ext files (*.bmp)|*.jpg";
openFileDialogA.FilterIndex = 2;
openFileDialogA.RestoreDirectory = true;
if (openFileDialogA.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialogA.OpenFile()) != null)
{
//读文件
string FileName = openFileDialogA.FileName.ToString();//获取文件路径;
//string allfileName = FileName.Substring(FileName.LastIndexOf("\\") + 1);//带后缀
if (FileName != null)
{
String currDir = Directory.GetCurrentDirectory();
using (StreamWriter sw = new StreamWriter(currDir + "/" + "configA.ini"))
{
sw.WriteLine(FileName);
sw.Dispose();
sw.Close();
//加载程序
// load_program_A();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("打开文件出错:" + ex.Message);
}
}
//保存修改
private void cmdSave_Click(object sender, EventArgs e)
{
String currDir = Directory.GetCurrentDirectory();
StreamReader st = new StreamReader(currDir + "/" + "configA.ini", Encoding.Default);
String fileStr = st.ReadLine();
result = common.save(fileStr, "****");
}
读取文件夹和文件路径简单的小功能
猜你喜欢
转载自blog.csdn.net/Bamboo265925/article/details/83105953
今日推荐
周排行