gpt4 book ai didi

c# - 为什么这个无效的文件路径//有效?

转载 作者:行者123 更新时间:2023-11-30 16:51:34 33 4
gpt4 key购买 nike

<分区>

我在某个Class1中有这个功能:

    public void function1(String path){
this.excel = new Application();
this.wbooks = excel.Workbooks;
this.wb = wbooks.Open(path);
String rootPath = wb.Path+"//..//..//";
String nPath = String.Format("{0}//Loads//{1}//{2}",rootPath,name1,name2);
String outputDir = String.Format("{0}//Input//{1}//{2}", rootPath, name1, name2);
String erroDir = String.Format("{0}//Erro//{1}//{2}", rootPath, name1, name2);
for(int i = 0; i < size; i++){
String[] array2 = File.ReadAllLines(String.Format("{0}//{1}_{2}.txt", nPath, name1, i.ToString()));
//code
Directory.CreateDirectory(erroDir);
File.WriteAllLines(String.Format("{0}//erro_{1}_{2}.txt", erroDir, name1, i.ToString()), array);
Directory.CreateDirectory(outputDir);
File.WriteAllLines(String.Format("{0}//output_{1}.txt", outputDir, name2), array);
}
}

这个函数来自一个类,在主函数中被这样调用:

String path = "C:\\Users\\myUsername\\Desktop\\myFolder\\";
Class1 temp = new Class1();
temp.function1(path);

为什么在函数中创建的路径有效?路径不应该是“\\”而不是“//”。

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com