可C#程序读取文本文件到内存中,然后将该对象传递给需要一个文件名的方法? [英] Can a C# program read a text file into memory and then pass that object to a method that requires a filename?

查看:694
本文介绍了可C#程序读取文本文件到内存中,然后将该对象传递给需要一个文件名的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#程序中,我通过My​​SQL的净连接器的MySqlBulkLoader功能导入大量的文本文件(300MB)到MySQL数据库中。

进口需要相当长的时间,结果几乎100%的磁盘使用它运行在Windows 2003 Server上。在试图加快程序NOW的进口拆分大的文件分成较小的块。

是否可以读取小的文件块(8MB)到内存(即数组),然后将它传递给MySQLBulkLoader作为一个文件?

批量加载器查找一个文件名路径:

  MySql.Data.MySqlClient.MySqlBulkLoader myBulk =新MySql.Data.MySqlClient.MySqlBulkLoader(连接);
 myBulk.Timeout = 10 * 60; /
 myBulk.TableName =some_table;
 myBulk.Local = TRUE;
 myBulk.LineTerminator = @\ N的;
 myBulk.FileName = aFile.FullName;
 myBulk.FieldTerminator =;
 

解决方案

内存不是文件,所以简单的答案是否定的。该方案是:

  1. 通过文件读,写它作为一个临时文件( System.IO.Path.GetTempFileName()是你的朋友在这里,对于这个名字给部分文件),并传递一个文件名MySqlBulkLoader
  2. 使用了RAM磁盘工具来创建一个基于内存的磁盘穿上全面300MB文件的副本,然后通过的文件路径MySqlBulkLoader。

In a C# program I am importing a large text file (300mb) into a MySQL database via the MySqlBulkLoader function of the MySql .Net Connector.

The import takes quite a long time and results in almost 100% disk usage on the Windows 2003 Server it is running on. In an attempt to speed up the import the program nows splits the big file into smaller chunks.

Would it be possible to read the small file chunk (8mb) into memory (ie array) and then pass it to the MySQLBulkLoader as a file?

The bulk loader looks for a filename path:

 MySql.Data.MySqlClient.MySqlBulkLoader myBulk = new MySql.Data.MySqlClient.MySqlBulkLoader(connection);                
 myBulk.Timeout = 10 * 60; /
 myBulk.TableName = "some_table";                
 myBulk.Local = true;
 myBulk.LineTerminator = @"\n";
 myBulk.FileName = aFile.FullName;
 myBulk.FieldTerminator = "";

解决方案

Memory isn't a file, so the short answer is no. The alternatives are:

  1. Read through the file, writing it out as a temporary file (System.IO.Path.GetTempFileName() is your friend here, for the name to give the partial file) and passing that filename to MySqlBulkLoader
  2. Use a "RAM Disk" tool to create a memory based disk to put a copy of the full 300Mb file on, then pass that files path to MySqlBulkLoader.

这篇关于可C#程序读取文本文件到内存中,然后将该对象传递给需要一个文件名的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆