0
NSString *pathOfFile = [NSString stringWithFormat:@"%@", file];
NSFileHandle *fh = [NSFileHandle fileHandleForUpdatingAtPath:pathOfFile];
[fh seekToFileOffset:30];
NSData *data = [fh readDataToEndOfFile];
[fh writeData:nil];
[[NSFileManager defaultManager] createFileAtPath:file contents:data attributes:nil];

ファイルの最初の 30 バイトを切り取りたい。私が得るものは次のとおりです。

mbp:Debug me$ hexdump -C File1
00000000  08 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000030  00 00 00 00 00 00 00 00  00 00 00 00 06 00 00 00  |................|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000070  00 00 00 00 00 00 00 00  03 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000000b0  00 00 00 00 02 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000000f0  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000120
mbp:Debug me$ hexdump -C File1
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 06 00  |................|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000050  00 00 00 00 00 00 00 00  00 00 03 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000090  00 00 00 00 00 00 02 00  00 00 00 00 00 00 00 00  |................|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000000d0  00 00 01 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000100

なぜカットされる代わりにゼロになるのですか?

4

1 に答える 1

0

全体として、私はこれを思いついた:

    NSString *pathOfFile = [NSString stringWithFormat:@"%@", file];
NSFileHandle *fh = [NSFileHandle fileHandleForUpdatingAtPath:pathOfFile];
[fh seekToFileOffset:30];
NSData *data = [fh readDataToEndOfFile];

NSRange range = NSMakeRange(30, [data length]-30);
NSData *refinedData = [data subdataWithRange:range];

[fh writeData:nil];
[[NSFileManager defaultManager] createFileAtPath:file contents:refinedData attributes:nil];
于 2012-12-02T20:20:07.203 に答える