将文件输入重定向到内存 [英] Redirecting File input to Memory

查看:298
本文介绍了将文件输入重定向到内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


以下是您的大家好消息:我们想知道是否有可能

将文件输入重定向到内存中的某个位置(例如一个字节数组)。


更具体地说,如果一个函数只将一个输入字符串指向

到一个文件路径(物理硬盘)驱动器位置),有没有办法欺骗你的b $ b函数读取内存位置而不是我们管理?这是

可能吗?


谢谢,


Rob

解决方案

我不知道你的意思是什么?..一个指向文件路径的输入字符串,

但是如果函数使用流,你可能会尝试使用MemoryStream。


" RobKinney1" < Ro ******** @ discussion.microsoft.comha scritto nel messaggio

news:43 ******************* *************** @ microsof t.com ...


你好,


这对你们所有人来说是一个令人头疼的问题:我们想知道它是否可能

将文件输入重定向到内存中的某个位置(比如说一个字节数组)

例子。


更具体地说,如果一个函数只取一个输入字符串

指示

到文件路径(物理硬盘位置),有没有办法欺骗



函数读取内存位置而不是我们管理?这是

可能吗?


谢谢,


Rob


文件只不过是媒体(硬盘驱动器)上的字节流。

您可以将字节数组存储在数据库表中,一个Hashtable(或Generics

等价物)等等。

所以你可以重写(或超载)你的方法

( 函数就像你所说的那样)查看Hashtable而不是文件来获取字节数据流,存储机制将是相同的。


但我认为没有办法欺骗一个现有的方法来做一些不同于它的代码的东西。


希望有所帮助。

彼得


-

网站: http: //www.eggheadcafe.com

UnBlog: http:/ /petesbloggerama.blogspot.com

短网址&更多: http://ittyurl.net


RobKinney1写道:


你好,


这对你们所有人来说是个蠢货:我们想知道是否有可能

将文件输入重定向到内存中的某个位置(比如一个字节数组)。


更具体地说,如果一个函数只取一个输入字符串

到一个文件路径(物理硬盘位置),有没有办法欺骗那个

函数来读取内存位置而不是我们管理的?这是

可能吗?


谢谢,


Rob


" Laura T."写道:


我不知道你的意思是什么?..一个指向文件路径的输入字符串,

但如果函数使用流,您可能会尝试使用MemoryStream。



你好Laura感谢您的回复。


请考虑以下代码:


//通常这就是编写代码的方式

//并且只采用字符串路径...它没有超载

//对于一个流对象(尽管我希望它是!!:〜})

GenericLibraryCall.OpenFile(" c:\ temp \ myFile.txt");


/ /从字节数组打开是否有一种棘手的方法?

byte [] myMemData = {/ *原始字节数据* /};


GenericLibraryCall .OpenFile(/ *不知何故技巧并重定向到字节数组* /);

我知道这听起来很奇怪,但我们使用的库只限于一个文件

路径。我们需要一种方法将输入重定向到一个字节数组,我们用它来管理。


这可能是不可能的。

谢谢,


Rob


Hello,

Here is a head scratcher for you all: We were wondering if it is possible
to redirect file input to a place in memory (say a byte array for example).

More specifically, if a function were to take only an input string directed
to a file path (physical hard drive location), is there a way to trick that
function into reading a memory location instead that we manage? Is this
possible?

Thanks,

Rob

解决方案

I''m not sure what you mean with "..an input string directed to a file path",
but if the functions use streams, you might try to use MemoryStream.

"RobKinney1" <Ro********@discussions.microsoft.comha scritto nel messaggio
news:43**********************************@microsof t.com...

Hello,

Here is a head scratcher for you all: We were wondering if it is
possible
to redirect file input to a place in memory (say a byte array for
example).

More specifically, if a function were to take only an input string
directed
to a file path (physical hard drive location), is there a way to trick
that
function into reading a memory location instead that we manage? Is this
possible?

Thanks,

Rob



A file is nothing more than a stream of bytes on the media (hard drive).
You can store a byte array in a database table, in a Hashtable (or Generics
equivalent) and so on.
So to the extent that you could rewrite (or overload) your method
("function" as you called it) to look to a Hashtable instead of a file for
that stream of byte data, the storage mechanics would be the same.

But I don''t think there is a way to "trick" an existing method to do
something different from what the code in it does.

Hope that helps.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"RobKinney1" wrote:

Hello,

Here is a head scratcher for you all: We were wondering if it is possible
to redirect file input to a place in memory (say a byte array for example).

More specifically, if a function were to take only an input string directed
to a file path (physical hard drive location), is there a way to trick that
function into reading a memory location instead that we manage? Is this
possible?

Thanks,

Rob


"Laura T." wrote:

I''m not sure what you mean with "..an input string directed to a file path",
but if the functions use streams, you might try to use MemoryStream.

Hello Laura Thank you for replying.

Consider the code below:

// normally this is how the code is written
// and only takes a string path... its not overloaded
// for a stream object (although I wish it was!! :~})
GenericLibraryCall.OpenFile("c:\temp\myFile.txt");

// Is there a tricky way to open from a byte array?
byte [] myMemData = { /* raw byte data here */};

GenericLibraryCall.OpenFile(/* somehow trick and redirect to byte array */);
I know this sounds odd, but the library we are using is restricted to a file
path. We need a way to redirect the input into a byte array that we are
managing.

This may not be possible.

Thanks,

Rob


这篇关于将文件输入重定向到内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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