用C复制文件

时间:2016-08-02 21:29:29

标签: c file copy

我尝试在新文件中复制文件,但它不起作用,因为输入是5133KB,输出是614byte ......出了什么问题?提前谢谢。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Dapper;


namespace AutorizarCreditoApp.Repositories
{
    public abstract class BaseRepository
    {
        private readonly string _ConnectionString;

        protected BaseRepository(string connectionString)
        {
            _ConnectionString = connectionString;
        }

        protected async Task<T> WithConnection<T>(Func<IDbConnection, Task<T>> getData)
        {
            try
            {
                using (var connection = new SqlConnection(_ConnectionString))
                {
                    await connection.OpenAsync(); // Asynchronously open a connection to the database
                    return await getData(connection); // Asynchronously execute getData, which has been passed in as a Func<IDBConnection, Task<T>>
                }
            }
            catch (TimeoutException ex)
            {
                throw new Exception(String.Format("{0}.WithConnection() experienced a SQL timeout", GetType().FullName), ex);
            }
            catch (SqlException ex)
            {
                throw new Exception(String.Format("{0}.WithConnection() experienced a SQL exception (not a timeout)", GetType().FullName), ex);
            }
        }

    }
}

1 个答案:

答案 0 :(得分:4)

您可能需要在系统上以二进制模式打开文件。从C.2011,§7.21.5.3:

  

rb 打开二进制文件进行阅读
   wb 截断为零长度或创建二进制文件以进行编写

所以:

FILE * input    =   fopen("input.wav", "rb");
FILE * output   =   fopen("output.wav", "wb");

原因是在某些系统上,某些嵌入的二进制字符可能会导致文本模式处理相信文件结尾已经遇到,即使文件中实际存在更多字节。