将文件截断为以字节为单位的大小

时间:2016-09-26 17:42:23

标签: vb.net

我有以下代码从现有文件创建另一个文件;生成的文件与原始文件相同。但是我需要生成的文件database.test只有原始文件的1024个字节(database.1)。有人可以给我一些快速解决方案,这是代码。以下是我的代码。

enum MyPointEnum {
    case zero
}

extension MyPointEnum: RawRepresentable {
    typealias RawValue = CGPoint

    init?(rawValue: CGPoint) {
        if rawValue == CGPoint.zero {
            self = .zero
        } else {
            return nil
        }
    }

    var rawValue: CGPoint {
        switch self {
        case .zero:
            return CGPoint.zero
        }
    }
}

print(MyPointEnum.zero.rawValue) //prints "(0.0, 0.0)\n"

1 个答案:

答案 0 :(得分:0)

感谢您的建议: -

我终于以这种方式工作了: -

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim data() As Byte = File.ReadAllBytes("C:\PROGRAMS\DATABASE.1")
        'File.WriteAllBytes("c:\programs\database.test", data)

        Using writer As BinaryWriter = New BinaryWriter(File.Open("c:\programs\database.test", FileMode.Create))

            Dim x As Single = data.Length - 1

            Dim l As Single = 0

            For l = 0 To 1023

                writer.Write(data(l))

            Next



        End Using



    End Sub