Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中打开csv文件时出错#_C#_Ilnumerics - Fatal编程技术网

C# 在C中打开csv文件时出错#

C# 在C中打开csv文件时出错#,c#,ilnumerics,C#,Ilnumerics,在c程序中打开和读取csv文件时,我被卡在这里。我刚开始研究ILNumerics来显示3D矩阵图,但随着 找不到文件“C:\Users\asd\Documents\Visual Studio 2013\Projects\matrixgraph\martix\bin\Debug\stats.csv”。 请帮帮我! 下面是代码 using System; using System.Collections.Generic; using System.ComponentModel; using Syst

在c程序中打开和读取csv文件时,我被卡在这里。我刚开始研究ILNumerics来显示3D矩阵图,但随着 找不到文件“C:\Users\asd\Documents\Visual Studio 2013\Projects\matrixgraph\martix\bin\Debug\stats.csv”。

请帮帮我! 下面是代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using ILNumerics;
using ILNumerics.Drawing;
using ILNumerics.Drawing.Plotting;



namespace martix
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void ilPanel1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string path = @"C:\Users\asd\Documents\Visual Studio 2013\Projects\matrixgraph\martix\bin\Debug\stats.csv";
            StreamReader sr = new StreamReader(File.Open(path, FileMode.Open));
            string dataLines = string.Empty;
            while (sr.Peek() != -1)
                dataLines += sr.ReadLine().Replace(";", ",") + "\n";
            sr.Close();
            dataLines = dataLines.Trim('\n');

            //Convert the data-string into an ILArray
            ILArray<int> AN = ILMath.csvread<int>(dataLines);

            //Create a new scene, which is the base for our graph
            var scene = new ILScene();
            using (ILScope.Enter())
            {
                //Convert all data points to float
                ILArray<float> A = ILMath.tosingle(AN);

                //Add a plot to the scene and configure it
                scene.Add(new ILPlotCube
                {
                    //Render in 3D
                    TwoDMode = false,

                    //Add 3 axes
                    Axes =
                    {

                        XAxis =
                        {
                            Label = { Text = "Price in $" },
                            GridMajor =
                            {
                                DashStyle = DashStyle.Dashed,
                                Color = Color.DarkGray,
                                Width = 1
                            }
                        },
                        YAxis =
                        {
                            Label = { Text = "Rating count" },
                            GridMajor =
                            {
                                DashStyle = DashStyle.Dashed,
                                Color = Color.DarkGray,
                                Width = 1
                            }
                        },
                        ZAxis =
                        {
                            Label = { Text = "Download count" }
                        }
                    },
                    //Add the data points
                    Children = {
                new ILPoints {
                    Positions = A
                },
            },
                    //Set start rotation for 3D rendered graph
                    Rotation = Matrix4.Rotation(new Vector3(1, 1, 1), 0.5f)
                });
            }

            //Add the scene to the ILPanel
            ilPanel1.Scene = scene;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用System.IO;
使用数字法;
使用数字。绘图;
使用ILNumerics.Drawing.Plotting;
名称空间martix
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
私有无效ilPanel1_加载(对象发送方、事件参数e)
{
}
私有void Form1\u加载(对象发送方、事件参数e)
{
字符串路径=@“C:\Users\asd\Documents\Visual Studio 2013\Projects\matrixgraph\martix\bin\Debug\stats.csv”;
StreamReader sr=新的StreamReader(File.Open(path,FileMode.Open));
string dataLines=string.Empty;
while(sr.Peek()!=-1)
dataLines+=sr.ReadLine()。替换(“;”,“,”)+“\n”;
高级关闭();
dataLines=dataLines.Trim('\n');
//将数据字符串转换为iArray
ILArray AN=ILMath.csvread(数据线);
//创建一个新场景,这是我们图形的基础
var scene=new ILScene();
使用(ILScope.Enter())
{
//将所有数据点转换为浮点
ILArray A=ILMath.tosingle(AN);
//将绘图添加到场景并对其进行配置
场景.添加(新ILPlotCube)
{
//三维渲染
TwoDMode=false,
//添加3个轴
斧头=
{
XAxis=
{
Label={Text=“价格单位$”},
格里德梅杰=
{
DashStyle=DashStyle.虚线,
Color=Color.DarkGray,
宽度=1
}
},
亚克斯=
{
Label={Text=“评级计数”},
格里德梅杰=
{
DashStyle=DashStyle.虚线,
Color=Color.DarkGray,
宽度=1
}
},
扎克西斯=
{
Label={Text=“下载计数”}
}
},
//添加数据点
儿童={
新点{
职位=A
},
},
//设置三维渲染图形的开始旋转
旋转=矩阵4.旋转(新矢量3(1,1,1),0.5f)
});
}
//将场景添加到ILP面板
ilPanel1.场景=场景;
}
}
}

可能是路径中的空格。没关系,你在使用逐字字符串

您确定路径可访问且不是网络映射路径吗?你能暂时移动你的文件吗?你似乎真的无法进入那条路

此外,您还应尝试执行以下操作以查明问题:

    System.IO.FileInfo fi = null;
    try
    {
      fi = new System.IO.FileInfo(path);
    }
    catch (ArgumentException) {... }
    catch (System.IO.PathTooLongException) {... }
    catch (NotSupportedException) {... }
    if (ReferenceEquals(fi, null))
    {
      ...
      // file name is not valid
    }
    else
    {
      ...
      // file name is valid... May check for existence by calling fi.Exists.

    }
编辑:
使用System.IO.Directory.GetFiles列出该文件夹中文件的确切名称,可能是文件名不同(stats.csv.csv),并且窗口资源管理器隐藏了扩展名

在尝试时得到了解决方案。我通过编程创建了csv文件,这次它读取了该文件

只是在路径前添加了几行,并修改了路径

StringBuilder csv = new StringBuilder();
            csv.AppendLine("112,113,222");
            string csvpath = @"C:\\stats\xyz.csv";
            File.AppendAllText(csvpath,csv.ToString());

            string path = @"C:\stats\xyz.csv";

就这样。无论如何,感谢您的帮助:)

您的
bin\debug
中没有
stats.csv
文件。。如果它在VS中引用到您的项目,请确保在
Properties->Copy to Output Directory
下是Copy Always或Copy If NewerWell,我已经多次确保了这一点,但它仍然会给我错误。目录真的是“martix”而不是“matrix”吗?还有,可能会有帮助。是的,项目名称是martix,虽然它必须是Matrix。我从目录复制了url。我甚至试图更改路径,但仍然是相同的错误。你确定没有使用该文件吗?在这种情况下,您将得到“进程无法访问文件'C:\bak\kofo\A csv.csv',因为它正被另一个进程使用”也可能是操作系统正在将资源管理器中显示的文件“stats.csv”读取为“stats.csv”。。。?使用System.IO.Directory.GetFiles列出该文件夹中文件的确切名称。。