+
95
-

回答

import Foundation

// Read file contents
do {
    let contents = try String(contentsOfFile: "/path/to/myfile.txt")
    print(contents)
} catch {
    print("Error reading file: \(error)")
}

// Write file contents
let textToWrite = "This is some text to write to the file."
do {
    try textToWrite.write(toFile: "/path/to/myfile.txt", atomically: true, encoding: .utf8)
} catch {
    print("Error writing file: \(error)")
}

网友回复

我知道答案,我要回答