簡體   English   中英

如何在可可網絡中復制文件

[英]how to copy a file on the network in cocoa

我想將所選文件從我的計算機復制到同一網絡上的另一台計算機。 我嘗試使用NSFileManager,但未成功。 請幫忙怎么做?

NSFileManager *fileManager = [[NSFileManager alloc] init];
NSString * filePath = [NSHomeDirectory() stringByAppendingPathComponent:
[NSString stringWithFormat:@"Documents/test"]];
NSString * filePath2 = [NSHomeDirectory() stringByAppendingPathComponent:
[NSString stringWithFormat:@"Shared/Test"]];
[fileManager copyItemAtPath:filePath toPath:filePath2 error:NULL];
[fileManager release];

2條建議:

1)根據文檔,此行中的錯誤應為“ nil”而不是“ NULL”

[fileManager copyItemAtPath:filePath toPath:filePath2 error:NULL];

2)也許代碼找不到文件。 我注意到您在路徑上沒有任何文件擴展名(也許“ test”應該是“ test.txt”?)。 即使您在Finder中看不到擴展名,大多數文件都有擴展名。 在這種情況下,獲取有關文件的信息以檢查其擴展名並修復代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM