如何从Html(1 MB)文件中断300 KB并且某些标记打开但由于使用C#完成300KB而未关闭 [英] How to break in size 300 KB from Html ( 1 MB) file and some tag are opens but not closed due to completed 300KB using C#

查看:108
本文介绍了如何从Html(1 MB)文件中断300 KB并且某些标记打开但由于使用C#完成300KB而未关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的女士/先生,





我想知道 - 如何使用C#从Html(1MB)中打破300 KB。

条件1.由于已完成300 KB,有些标签已打开但未关闭。



如何维护结束标签以及如何打开下一个标签?

请建议我。





例如 - 我有1个html文件,大小是1 MB。



然后我想从html文件中打破300 kB。



包含的文件标签 - p,div,表头(h1到h6)。



请帮助我。

解决方案

[更新]



试试这个。



<前lang =cs> static void FileSplit( string ipath)
{
// 打开输入文件
使用(FileSt ream fsi = File.OpenRead(ipath))
{
bool completed = false ; // 在创建所有零件时完成
int i = 0 ; // part index
byte [] buff = new byte [ 1024 ]; // 读/写缓冲区

while (!已完成)
{
// 零件文件路径
string opath = string .Format( {0} _ {1},ipath,i ++);
// 已处理零件尺寸
int partsize = 0 ;

// 打开零件文件
using (FileStream fso = File.Create(opath))
{
// 最大零件尺寸要求
(partsize < 300000
{
// 从输入文件中读取
int n = fsi.Read(buff, 0 1024 );
if (n > 0
{
partsize + = n;
// 写入零件文件
fso.Write(buff, 0 ,n);
}
completed =(n < 1024 || i > 10 );
// 完成后中断循环
if (已完成)
break ;
}
}
}
}
} // 文件结束分割


Dear Madam/Sir,


I want to know -How to break 300 KB from Html(1MB) using C#.
condition 1. some tags are open but not closed due to completed 300 KB.

How to maintain closing tags and How to open next tags ?
Please suggest me.


FOr eg- I have 1 html file and size is 1 MB.

Then I want to break in 300 kB from html file.

file included tags - p,div,table header(h1 to h6).

Please help me.

解决方案

[UPDATED]

try this.

static void FileSplit(string ipath)
{
    // open input file
    using (FileStream fsi = File.OpenRead(ipath))
    {
        bool completed = false; // completed when all parts created
        int i = 0; // part index
        byte[] buff = new byte[1024]; // read/write buffer

        while (!completed)
        {
            // part file path
            string opath = string.Format("{0}_{1}", ipath, i++);
            // processed part size
            int partsize = 0;

            // open part file
            using (FileStream fso = File.Create(opath))
            {
                // requirement for max part size
                while (partsize < 300000)
                {
                    // read from input file
                    int n = fsi.Read(buff, 0, 1024);
                    if (n > 0)
                    {
                        partsize += n;
                        // write to part file
                        fso.Write(buff, 0, n);
                    }
                    completed = (n < 1024 || i > 10);
                    // break loop if completed
                    if (completed)
                        break;
                }
            }
        }
    }
} // end of file split


这篇关于如何从Html(1 MB)文件中断300 KB并且某些标记打开但由于使用C#完成300KB而未关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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