gpt4 book ai didi

objective-c - 在应用程序启动时从桌面读取文本文件

转载 作者:太空狗 更新时间:2023-10-30 04:01:28 26 4
gpt4 key购买 nike

我需要在启动时在 NSTextView 中显示位于用户桌面上的文本文件的内容。我的代码无法正常工作——是否偏离轨道?

NSError *err = nil;

NSString *filepath = @"~/Desktop/test.txt";

NSString *file = [NSString stringWithContentsOfFile:filepath
encoding:NSUTF8StringEncoding
error:&err];

if(!file) {

}

[textView setString:file];

最佳答案

@闪。对于那个很抱歉。

我是这样修复的:

 NSError *err = nil;

NSString *filepath = @"~/Desktop/test.txt";
filepath = [filepath stringByExpandingTildeInPath];

NSString *file = [NSString stringWithContentsOfFile:filepath
encoding:NSUTF8StringEncoding
error:&err];

if(!file) {

}

[textView setString:file];

关于objective-c - 在应用程序启动时从桌面读取文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6241060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com