- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 swift ubuntu docker:https://github.com/IBM-Swift/swift-ubuntu-docker
然后尝试将文件从路径 A 复制到路径 B。在执行过程中我得到了 fatal error :
fatal error: copyItem(atPath:toPath:) is not yet implemented: file Foundation/NSFileManager.swift, line 376
Illegal instruction
命令:
# swift --version
回应
Swift version 3.1.1 (swift-3.1.1-RELEASE)
Target: x86_64-unknown-linux-gnu
在网上查到了应该实现的资料:
https://bugs.swift.org/browse/SR-2639
有人可以帮忙吗?谢谢!
最佳答案
copyItem(atPath:toPath:)
未在 Swift 3.1 branch 上实现Linux 的基础框架:
open func copyItem(atPath srcPath: String, toPath dstPath: String) throws {
NSUnimplemented()
}
例如,您可以做的是
let fm = FileManager.default
if let contents = fm.contents(atPath: srcPath) {
if !fm.createFile(atPath: destPath, contents: contents, attributes: nil) {
print("cannot write destination file")
}
} else {
print("cannot read source file")
}
这是 copyItem(atPath:toPath:)
的简化版本在 master branch 上实现.
如果文件很大,那么你可能需要分块复制而不是将整个文件读入内存,例如这样:
guard let srcFile = FileHandle(forReadingAtPath: srcPath) else {
fatalError("cannot open source file")
}
guard let destFile = FileHandle(forWritingAtPath: destPath) else {
fatalError("cannot open destination file")
}
while case let data = srcFile.readData(ofLength: 1024 * 1024), data.count > 0 {
destFile.write(data)
}
srcFile.closeFile()
destFile.closeFile()
关于swift 3.1.1.-在 linux copyItem 上发布(atPath :toPath:) is not yet implemented,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44741037/
我正在尝试使用以下代码将文件 StandardQuestions.csv 复制到新文件名: String standardQuestions = "StandardQuestions.csv"; if
这是File类(jdk7)的toPath()方法 private volatile transient Path filePath; public Path toPath() {
安卓工作室 3.4.2 安卓6.0 dependencies { annotationProcessor "org.androidannotations:androidannotations:
我正在尝试将一个只读但包含文件的文件夹复制到另一个位置。当我使用 -copyItemAtPath:toPath:error: 时,它复制文件夹,但不复制文件。演示该错误的示例代码如下。 在这种情况下,
使用Stream-upload插件上传文件时出现问题.问题如下: java.lang.NoSuchMethodError: java.io.File.toPath()Ljava/nio/file/Pa
我有一个 importFile 存储在 NSString* importFile(用 NSLog %@ 打印): /var/mobile/Applications/5CE1D252-E56A-4AAC
Java 有一个内置的内容类型检测器,但是,它自然会错过一些文件类型。 Files.probeContentType(new File(".ttf").toPath()); 看起来好像该实现允许添加更
我正在尝试使用以下命令将 sqlite 数据库添加到应用程序中:CoreData: Preload Data in Your iOS App 按照教程我遇到了一个问题: [NSFileManager
NSFileManager 有一个方法来进行复制。 - (BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath erro
这纯粹是一个好奇项目——解决方案结果是检查返回值而不是错误——但是这段代码已经有几个月了,而且那个特定的部分还没有过去的问题(可能与此代码仅在应用程序首次运行时运行有关?)。 我有一段代码,我将文件从
我正在尝试在 Android Java 上克隆存储库,但在调用方法 toPath() 时出现错误。显然 File 对象没有 toPath() 方法。 public void gitClone() th
我正在与一个团队一起开发,使用的是所有图像完全相同的 mac。使用我编写代码的机器,我可以以编程方式创建然后写入 pList 文件。但是当我使用我的家用机器(相同的图像)或当我的队友在他们的机器上测试
在我最新的应用程序更新中,我将每个用户的 .sqlite 数据库移动到不同的目录。我正在使用 Core Data 方法 migratePersistentStore:toURL:options:wit
我正在使用 swift ubuntu docker:https://github.com/IBM-Swift/swift-ubuntu-docker 然后尝试将文件从路径 A 复制到路径 B。在执行过
我正在使用 soanr 来检查我的 java 代码,有一个问题表明,我们应该使用 java.nio.file.Files.newInputStream(myfile.toPath()) 而不是 new
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc
我是一名优秀的程序员,十分优秀!