- 浏览: 607218 次
- 性别:
- 来自: 郑州
文章分类
最新评论
-
AlanKay:
Mart_dai 写道Hi 齐晓威_518,我想问问,在exc ...
java 后台 Excel 文件生成后转化为字节流 -
18335864773:
国内的pageoffice插件也可以生成excel。也可以用流 ...
java 后台 Excel 文件生成后转化为字节流 -
JAVA_CLASSm:
你好,请问这个还有源码吗?我刚开始接触这个,想要源码学习一下. ...
同一账号不能多地登录(限制同一账号同一时刻只能一个用户登录使用,向QQ一样) -
pangjinquan:
...
前台JS获取后台的Json数据, 动态创建table并填充数据--转自一位朋友 -
lvjun106:
这是增加删除列,,,,
JQuery自动为表格增加一列
来自: http://blog.sina.com.cn/s/blog_5245a6580100vw5r.html
和 http://blog.sina.com.cn/s/blog_5245a6580100w7wd.html
好吧,我想我的写写了。我用的方法很简单,首先先把大文件转换成byte数组,然后调用webservice将byte数组转换成文件。但是如果文件大小超过25M的时候会超时,所以我将这个数组分批传输,每一批都是一个20M的byte数组,然后把这些数组追加,最后形成一个完整的文件。注意在形成文件的时候要判断要生成的文件是否存在,否则如果文件已经存在的话,该文件不会被覆盖,而是被追加。
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace controtest
{
classProgram
{
static byte[] buffer;
static void Main(string[] args)
{
string rst =string.Empty ;
PartnerWebservice.PartnerServices pa = newPartnerWebservice.PartnerServices();
string path =System.Configuration.ConfigurationSettings.AppSettings["path"].ToString();//文件的存放目录
string filename =System.Configuration.ConfigurationSettings.AppSettings["name"].ToString();//文件名称
Console.WriteLine("ConvertToBinary start at"+DateTime.Now.ToString());
buffer = ConvertToBinary(path);//将文件转换成byte数组
int index = buffer.Length /20971520;//20971520bite就是20M,1*1024*1024*20
index += buffer.Length % 20971520 == 0 ? 0 : 1;
bool ifEnd=false;//是否为最后一组
for (int ii = 0; ii < index; ii++)
{
if (ii == index - 1)
ifEnd = true;
Console.WriteLine("ConvertToBinary end at " +DateTime.Now.ToString());
Console.WriteLine("Trans start at " +DateTime.Now.ToString());
pa.TransFile(ConvertToBinary(ii, ifEnd),"XXXX.XXX");//分批传输数据,追加到XXXX.XXX文件,如果不存在会自动创建
Console.WriteLine(rst);
Console.WriteLine("Trans end at " + DateTime.Now.ToString());
}
Console.ReadLine();
}
public static byte[] ConvertToBinary(string Path)
{
FileStream stream = new FileInfo(Path).OpenRead();
byte[] buffer = new byte[stream.Length];
Console.WriteLine("The lenght of the file is"+buffer.Length);
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
return buffer;
}
public static byte[] ConvertToBinary(int index,boolifEnd)//index是第几批,从0开始这个方法名跟上边那个重名了注意区别,两个方法意义是不一样的,我懒得改了
{
//20971520
//index = buffer.Length / 20971520;
//index += buffer.Length % 20971520 == 0 ? 0 : 1;
byte[] bys;//临时二进制数组,最大20M
if (ifEnd == false)
{
bys = new byte[20971520];
for (int ii = 20971520 * index; ii < 20971520 *(index + 1); ii++)
{
bys[ii - 20971520 * index] = buffer[ii];
}
}
else
{
bys = new byte[buffer.Length - 20971520 * (index )];
for (int ii = 20971520 * index; ii < buffer.Length;ii++)
{
bys[ii - 20971520 * index] = buffer[ii];
}
}
Console.WriteLine("The length of the current buffer is " +bys.Length);
return bys;
}
public static byte[] ChangeFileToByte(string path)
{
FileStream stream = new FileInfo(path).OpenRead();
byte[] Filebuffer = new byte[stream.Length];
stream.Read(Filebuffer, 0, Convert.ToInt32(stream.Length));
return Filebuffer;
}
}
}
以下是webservice部分的方法
[WebMethod(Description = "TransFile")]
publicstring TransFile(byte[] fileBt, stringfileName)
{
string rst = "successful";
if (fileBt.Length == 0)
return "The length of the File"+fileName +"is 0";
string filePath =System.Configuration.ConfigurationManager.AppSettings["CSVPath"].ToString(); //文件路径
//FileStream fstream = File.Create(filePath + fileName,fileBt.Length);
//FileStream fstream = File.AppendAllText(
FileStream fstream = new FileStream(filePath + fileName,FileMode.Append);
try
{
//MemoryStream m = new MemoryStream(fileBt);
//m.WriteTo(fstream);
fstream.Write(fileBt, 0,fileBt.Length); //二进制转换成文件
fstream.Close();
//rst += "\r\n";
rst += "File Name is:" + fstream.Name + "\r\n";
rst += "File Lenght is:" + fstream.Length + "\r\n";
rst += "File Position is:" + fstream.Position +"\r\n";
}
catch (Exception ex)
{
//抛出异常信息
rst = ex.ToString();
}
finally
{
fstream.Close();
}
StringBuilder sbd = new StringBuilder();
sbd.AppendLine(rst);
return sbd.ToString();
}
webservice大文件传输(优化)
控制台程序,没有注释,在我本机10G数据量没有问题
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace controtest
{
classProgram
{
static void Main(string[] args)
{
string rst = string.Empty;
PartnerWebservice.PartnerServices pa = newPartnerWebservice.PartnerServices();
string path =System.Configuration.ConfigurationSettings.AppSettings["path"].ToString();
string filename =System.Configuration.ConfigurationSettings.AppSettings["name"].ToString();
Console.WriteLine("ConvertToBinary start at " +DateTime.Now.ToString());
long fileLength = LengthOfFile(path);
long countOfPk =fileLength /Convert.ToInt64(20971520);
countOfPk += fileLength % 20971520 == 0 ? 0 : 1;
Console.WriteLine("The count of the pakeg is " + countOfPk);
bool ifEnd = false;
Console.WriteLine("Start");
Console.WriteLine();
for (long ii = 0; ii < countOfPk; ii++)
{
if (ii == countOfPk - 1)
ifEnd = true;
Console.WriteLine("Trans start at " +DateTime.Now.ToString());
Console.WriteLine("The index is "+(ii+1)+"/"+countOfPk);
if (ii == 0)
pa.TransFile(ConvertToBinary(ii, ifEnd, fileLength), "test.CSV",true);
else
pa.TransFile(ConvertToBinary(ii, ifEnd, fileLength), "test.CSV",false);
Console.Write(rst);
Console.WriteLine("Trans end at " + DateTime.Now.ToString());
Console.WriteLine();
}
Console.WriteLine(LengthOfFile(path));
//Console.WriteLine(ConvertToBinary(path).Length);
Console.ReadLine();
}
public static byte[] ConvertToBinary(string Path)
{
FileStream stream = new FileInfo(Path).OpenRead();
byte[] buffer = new byte[stream.Length];
Console.WriteLine("The lenght of the file is"+buffer.Length);
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
return buffer;
}
/// <summary>
/// 获取文件大小
/// </summary>
/// <paramname="path"></param>
///<returns></returns>
public static long LengthOfFile(stringpath)
{
FileInfo fi = new FileInfo(path);
return fi.Length;
}
public static byte[] ConvertToBinary(long index,bool ifEnd,longfileLenght)
{
//20971520
byte[] bysFile;//临时二进制数组,最大20M
//index = buffer.Length / 20971520;
//index += buffer.Length % 20971520 == 0 ? 0 : 1;
//byte[] bys;//临时二进制数组,最大20M
if (ifEnd == false)
{
bysFile = GetFileBloc(20971520 * index, 20971520);
}
else
{
bysFile = GetFileBloc(20971520 * index, fileLenght - 20971520 *(index));
}
Console.WriteLine("The length of the current buffer is " +bysFile.Length);
return bysFile;
}
public static byte[] ChangeFileToByte(string path)
{
FileStream stream = new FileInfo(path).OpenRead();
byte[] Filebuffer = new byte[stream.Length];
stream.Read(Filebuffer, 0, Convert.ToInt32(stream.Length));
return Filebuffer;
}
/// <summary>
/// 获取文件二进制块
/// </summary>
/// <paramname="path"></param>
/// <paramname="byteIndex"></param>
/// <paramname="length"></param>
///<returns></returns>
public static byte[] GetFileBloc( long byteIndex, longlength)
{
string path =System.Configuration.ConfigurationSettings.AppSettings["path"].ToString();
FileStream stream = new FileInfo(path).OpenRead();
stream.Position = byteIndex;
byte[] Filebuffer = new byte[length];
stream.Read(Filebuffer,0,Convert.ToInt32( length));
return Filebuffer;
}
}
}
以下是webservice部分
[WebMethod(Description = "TransFile")]
publicstring TransFile(byte[] fileBt, stringfileName,bool ifCreate)
{
string rst = "0";
if (fileBt.Length == 0)
return rst ;
string filePath =System.Configuration.ConfigurationManager.AppSettings["CSVPath"].ToString(); //文件路径
//FileStream fstream = File.Create(filePath + fileName,fileBt.Length);
//FileStream fstream = File.AppendAllText(
FileStream fstream;
if(ifCreate)
fstream = new FileStream(filePath + fileName,FileMode.Create);
else
fstream = new FileStream(filePath + fileName, FileMode.Append);
try
{
//MemoryStream m = new MemoryStream(fileBt);
//m.WriteTo(fstream);
fstream.Write(fileBt, 0,fileBt.Length); //二进制转换成文件
//rst += "\r\n";
rst = fstream.Length.ToString() ;
fstream.Close();
}
catch (Exception ex)
{
//抛出异常信息
rst = ex.ToString();
}
finally
{
fstream.Close();
}
return rst;
}
和 http://blog.sina.com.cn/s/blog_5245a6580100w7wd.html
好吧,我想我的写写了。我用的方法很简单,首先先把大文件转换成byte数组,然后调用webservice将byte数组转换成文件。但是如果文件大小超过25M的时候会超时,所以我将这个数组分批传输,每一批都是一个20M的byte数组,然后把这些数组追加,最后形成一个完整的文件。注意在形成文件的时候要判断要生成的文件是否存在,否则如果文件已经存在的话,该文件不会被覆盖,而是被追加。
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace controtest
{
classProgram
{
static byte[] buffer;
static void Main(string[] args)
{
string rst =string.Empty ;
PartnerWebservice.PartnerServices pa = newPartnerWebservice.PartnerServices();
string path =System.Configuration.ConfigurationSettings.AppSettings["path"].ToString();//文件的存放目录
string filename =System.Configuration.ConfigurationSettings.AppSettings["name"].ToString();//文件名称
Console.WriteLine("ConvertToBinary start at"+DateTime.Now.ToString());
buffer = ConvertToBinary(path);//将文件转换成byte数组
int index = buffer.Length /20971520;//20971520bite就是20M,1*1024*1024*20
index += buffer.Length % 20971520 == 0 ? 0 : 1;
bool ifEnd=false;//是否为最后一组
for (int ii = 0; ii < index; ii++)
{
if (ii == index - 1)
ifEnd = true;
Console.WriteLine("ConvertToBinary end at " +DateTime.Now.ToString());
Console.WriteLine("Trans start at " +DateTime.Now.ToString());
pa.TransFile(ConvertToBinary(ii, ifEnd),"XXXX.XXX");//分批传输数据,追加到XXXX.XXX文件,如果不存在会自动创建
Console.WriteLine(rst);
Console.WriteLine("Trans end at " + DateTime.Now.ToString());
}
Console.ReadLine();
}
public static byte[] ConvertToBinary(string Path)
{
FileStream stream = new FileInfo(Path).OpenRead();
byte[] buffer = new byte[stream.Length];
Console.WriteLine("The lenght of the file is"+buffer.Length);
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
return buffer;
}
public static byte[] ConvertToBinary(int index,boolifEnd)//index是第几批,从0开始这个方法名跟上边那个重名了注意区别,两个方法意义是不一样的,我懒得改了
{
//20971520
//index = buffer.Length / 20971520;
//index += buffer.Length % 20971520 == 0 ? 0 : 1;
byte[] bys;//临时二进制数组,最大20M
if (ifEnd == false)
{
bys = new byte[20971520];
for (int ii = 20971520 * index; ii < 20971520 *(index + 1); ii++)
{
bys[ii - 20971520 * index] = buffer[ii];
}
}
else
{
bys = new byte[buffer.Length - 20971520 * (index )];
for (int ii = 20971520 * index; ii < buffer.Length;ii++)
{
bys[ii - 20971520 * index] = buffer[ii];
}
}
Console.WriteLine("The length of the current buffer is " +bys.Length);
return bys;
}
public static byte[] ChangeFileToByte(string path)
{
FileStream stream = new FileInfo(path).OpenRead();
byte[] Filebuffer = new byte[stream.Length];
stream.Read(Filebuffer, 0, Convert.ToInt32(stream.Length));
return Filebuffer;
}
}
}
以下是webservice部分的方法
[WebMethod(Description = "TransFile")]
publicstring TransFile(byte[] fileBt, stringfileName)
{
string rst = "successful";
if (fileBt.Length == 0)
return "The length of the File"+fileName +"is 0";
string filePath =System.Configuration.ConfigurationManager.AppSettings["CSVPath"].ToString(); //文件路径
//FileStream fstream = File.Create(filePath + fileName,fileBt.Length);
//FileStream fstream = File.AppendAllText(
FileStream fstream = new FileStream(filePath + fileName,FileMode.Append);
try
{
//MemoryStream m = new MemoryStream(fileBt);
//m.WriteTo(fstream);
fstream.Write(fileBt, 0,fileBt.Length); //二进制转换成文件
fstream.Close();
//rst += "\r\n";
rst += "File Name is:" + fstream.Name + "\r\n";
rst += "File Lenght is:" + fstream.Length + "\r\n";
rst += "File Position is:" + fstream.Position +"\r\n";
}
catch (Exception ex)
{
//抛出异常信息
rst = ex.ToString();
}
finally
{
fstream.Close();
}
StringBuilder sbd = new StringBuilder();
sbd.AppendLine(rst);
return sbd.ToString();
}
webservice大文件传输(优化)
控制台程序,没有注释,在我本机10G数据量没有问题
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace controtest
{
classProgram
{
static void Main(string[] args)
{
string rst = string.Empty;
PartnerWebservice.PartnerServices pa = newPartnerWebservice.PartnerServices();
string path =System.Configuration.ConfigurationSettings.AppSettings["path"].ToString();
string filename =System.Configuration.ConfigurationSettings.AppSettings["name"].ToString();
Console.WriteLine("ConvertToBinary start at " +DateTime.Now.ToString());
long fileLength = LengthOfFile(path);
long countOfPk =fileLength /Convert.ToInt64(20971520);
countOfPk += fileLength % 20971520 == 0 ? 0 : 1;
Console.WriteLine("The count of the pakeg is " + countOfPk);
bool ifEnd = false;
Console.WriteLine("Start");
Console.WriteLine();
for (long ii = 0; ii < countOfPk; ii++)
{
if (ii == countOfPk - 1)
ifEnd = true;
Console.WriteLine("Trans start at " +DateTime.Now.ToString());
Console.WriteLine("The index is "+(ii+1)+"/"+countOfPk);
if (ii == 0)
pa.TransFile(ConvertToBinary(ii, ifEnd, fileLength), "test.CSV",true);
else
pa.TransFile(ConvertToBinary(ii, ifEnd, fileLength), "test.CSV",false);
Console.Write(rst);
Console.WriteLine("Trans end at " + DateTime.Now.ToString());
Console.WriteLine();
}
Console.WriteLine(LengthOfFile(path));
//Console.WriteLine(ConvertToBinary(path).Length);
Console.ReadLine();
}
public static byte[] ConvertToBinary(string Path)
{
FileStream stream = new FileInfo(Path).OpenRead();
byte[] buffer = new byte[stream.Length];
Console.WriteLine("The lenght of the file is"+buffer.Length);
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
return buffer;
}
/// <summary>
/// 获取文件大小
/// </summary>
/// <paramname="path"></param>
///<returns></returns>
public static long LengthOfFile(stringpath)
{
FileInfo fi = new FileInfo(path);
return fi.Length;
}
public static byte[] ConvertToBinary(long index,bool ifEnd,longfileLenght)
{
//20971520
byte[] bysFile;//临时二进制数组,最大20M
//index = buffer.Length / 20971520;
//index += buffer.Length % 20971520 == 0 ? 0 : 1;
//byte[] bys;//临时二进制数组,最大20M
if (ifEnd == false)
{
bysFile = GetFileBloc(20971520 * index, 20971520);
}
else
{
bysFile = GetFileBloc(20971520 * index, fileLenght - 20971520 *(index));
}
Console.WriteLine("The length of the current buffer is " +bysFile.Length);
return bysFile;
}
public static byte[] ChangeFileToByte(string path)
{
FileStream stream = new FileInfo(path).OpenRead();
byte[] Filebuffer = new byte[stream.Length];
stream.Read(Filebuffer, 0, Convert.ToInt32(stream.Length));
return Filebuffer;
}
/// <summary>
/// 获取文件二进制块
/// </summary>
/// <paramname="path"></param>
/// <paramname="byteIndex"></param>
/// <paramname="length"></param>
///<returns></returns>
public static byte[] GetFileBloc( long byteIndex, longlength)
{
string path =System.Configuration.ConfigurationSettings.AppSettings["path"].ToString();
FileStream stream = new FileInfo(path).OpenRead();
stream.Position = byteIndex;
byte[] Filebuffer = new byte[length];
stream.Read(Filebuffer,0,Convert.ToInt32( length));
return Filebuffer;
}
}
}
以下是webservice部分
[WebMethod(Description = "TransFile")]
publicstring TransFile(byte[] fileBt, stringfileName,bool ifCreate)
{
string rst = "0";
if (fileBt.Length == 0)
return rst ;
string filePath =System.Configuration.ConfigurationManager.AppSettings["CSVPath"].ToString(); //文件路径
//FileStream fstream = File.Create(filePath + fileName,fileBt.Length);
//FileStream fstream = File.AppendAllText(
FileStream fstream;
if(ifCreate)
fstream = new FileStream(filePath + fileName,FileMode.Create);
else
fstream = new FileStream(filePath + fileName, FileMode.Append);
try
{
//MemoryStream m = new MemoryStream(fileBt);
//m.WriteTo(fstream);
fstream.Write(fileBt, 0,fileBt.Length); //二进制转换成文件
//rst += "\r\n";
rst = fstream.Length.ToString() ;
fstream.Close();
}
catch (Exception ex)
{
//抛出异常信息
rst = ex.ToString();
}
finally
{
fstream.Close();
}
return rst;
}
发表评论
-
使用xmlhttp.send()方法的参数来传递大容量的数据
2015-02-28 10:13 811使用xmlhttp.send()方法的参数来传递大容量的数据 ... -
java千万级别数据生成文件思路和优化
2015-02-28 10:01 704一年前写过一个百万级别数据库数据生成配置xml文件的程序,程序 ... -
项目管理总结
2015-02-25 11:09 947【一】开发环境和测试 ... -
因为无能为力,所以顺其自然。因为心无所恃,所以随遇而安
2014-10-19 16:12 719在很久以前,有一个寺院,里面住着一老一小两位和尚。 有一天 ... -
从程序员到项目经理-转
2014-09-23 21:17 1406从薪水上看,当然是资 ... -
何为30而立?如何把握好成功的方向,才能驾驶自己的人生
2014-02-15 17:47 884你所有不曾料想过的问题,都会随着时间的推移而与你不期而遇;你所 ... -
你平静的生活或许会在某个不可预见的时刻被彻底打碎
2014-03-02 16:50 823故事一:年轻人被闹钟叫醒了,飞速地穿戴,洗漱,用早点,是的他今 ... -
网址-技术网站-jquery
2014-04-09 21:43 651技术网站-jquery http://site518.n ... -
ITCYC中一位同行发表的电子书,收藏下来方便下载观看
2014-03-18 23:19 712ITCYC中一位同行发表的电子书,收藏下来方便下载观看 ... -
原创: 莫叹人间苦与乐,天下何处无净境
2013-10-27 14:02 728莫叹人间苦与乐,天下何处无净境 试问阅者,你 ... -
评名言:大象无形,至刚易折
2013-10-27 13:59 931大象无形,至刚易折 古人云:大象的力量和体形甚 ... -
你会在公司工作多久?
2013-09-28 12:17 14561.介绍你自己 这个问题 ... -
感悟,是该换工作的时候了
2013-09-18 19:52 770一个人最大的价值不是创造了什么,而是给予了什么,生命如何短暂也 ... -
驾考科目三考试技巧
2013-09-17 17:19 808拐弯要减速减档,打转弯灯和鸣笛,不允许挂空挡。 直线或 ... -
亲爱的大叔
2013-09-01 21:23 1159要不是当初匆忙的脚步 迷途的我早已经放弃追逐 人生有太多反复难 ... -
21世纪将淘汰的八种人
2013-07-28 21:39 1028第一种被淘汰的人是“ ... -
合作法则
2013-07-28 21:34 7631、不与私欲太重的人合作,因为他们看不见别人的付出,只在意自己 ... -
品万像,会生活
2013-05-25 15:44 784不同的选择有不同的命运 ... -
蓦然回首--发现自己已不再青春年少
2013-01-16 22:44 1604岁月如流,年华似水,蓦然回首发现自己依然在原地,镜中的自己 ... -
系统 开始——运行——命令集锦
2012-11-29 09:16 882winver---------检查Windows版本 wmi ...
相关推荐
下载后会有2个文件一个 UpFile模拟上传客户端, WebServer模拟服务器接收端。 环境是VS2010.
java调用windows系统的com组件,用jacob来处理。JACOB一个Java-COM中间件.通过这个组件你可以在Java应用程序中调用COM组件和Win32程序库。
C#实现基于webService 的文件传输程序,WEB服务的创建和调用,并WSE3.0、后台线程的创建模式、文件哈希校验
webservice 实现文件的传输。
基于webservice的文件传输。从理论角度详细说明了webservice传输文件的基本原理
电子书的概述:webservice文件传输 源代码的说明:包括客户端和服务器端的简单介绍 文档的片段:包括客户端和服务器端的讲解
WebService大文件断点续传[归纳].pdf
WebService中上传文件
javaweb service大文件上传下载 DataHandler
使用webservice实现json文件传输,包含压包解包。在jdk1.6,myeclipse10下测试成功.完整源码
VS2013、C++语言、SOAP实现调用webservice接口,接口包括上传文件、日志、获取消息等等。全部源码+DEMO示例
NULL 博文链接:https://exceptioneye.iteye.com/blog/1325187
用webservice作为服务器端,以流的方式实现文件的上传和下载,可以自动调用winrar进行压缩和加密,支持多线程和断点续传功能,默认是16K一个包,全部源码,已经在实际项目中应用。客户端有winform和服务两种方式的...
mule一些demo(webservice,http,文件传输,数据库连接等)
基于spring+cxf实现用户文件传输的webservice.docx,webservice的小例子,对学习很有用,欢迎大家下载
使用webService上传文件,代码写的简单,所以没有注释; 基础型的,没有优化,大家可以根据自己的需求更改成你想要的~~
WebService 程序利用 TSOAPAttachment 来上传或下载文件
Webservice方式的文件上传和下载,采用c#开发,代码说明详细说明了配置,并解决大文件上传的异常处理。
win7环境,利用VC和gsoap实现webservice文件传输
JAVA的WebService支持,SOA(Service-Oriented Architecture)面向服务架构是一种思想,它将应用程序的不同功能单元 通过中立的契约(独立于硬件平台、操作系统和编程语言)联系起来,使得各种形式的功能 单元更好的...