Rod*_*ney 4 .net c# bytearray file
我从文件系统读取文件并将其FTP到FTP服务器.我现在有一个跳过第一行的请求(它是带有标题信息的CSV).我想我可以用stream.Read方法(或写方法)的Offset以某种方式做到这一点,但我不知道如何从单行转换字节数组偏移量.
我如何计算偏移量,告诉它只读取文件的第二行?
谢谢
// Read the file to be uploaded into a byte array
stream = File.OpenRead(currentQueuePathAndFileName);
var buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
// Get the stream for the request and write the byte array to it
var reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
return request;
Run Code Online (Sandbox Code Playgroud)
您应该使用File.ReadAllLines.它返回字符串数组.然后只会strArray.Skip(1)返回除第一行之外的所有行.
UPDATE
这是代码:
var stringArray = File.ReadAllLines(fileName);
if (stringArray.Length > 1)
{
stringArray = stringArray.Skip(1).ToArray();
var reqStream = request.GetRequestStream();
reqStream.Write(stringArray, 0, stringArray.Length);
reqStream.Close();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1531 次 |
| 最近记录: |