如何找回短信

发布于 2024-10-31 00:03:58 字数 519 浏览 3 评论 0原文

这是我如何保存文本的代码

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [documentPaths objectAtIndex:0];
    NSString *documentTXTPath = [documentsDirectory stringByAppendingPathComponent:@"myFile.plist"];
    NSString *savedString = _textView.text;
    //NSString *saveString=_textView2.text;
    [savedString writeToFile:documentTXTPath atomically:YES ];

请告诉我如何检索它。请帮我。以及如何在我的项目本身中制作plist。 谢谢。

This is code how I save text

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [documentPaths objectAtIndex:0];
    NSString *documentTXTPath = [documentsDirectory stringByAppendingPathComponent:@"myFile.plist"];
    NSString *savedString = _textView.text;
    //NSString *saveString=_textView2.text;
    [savedString writeToFile:documentTXTPath atomically:YES ];

Please tell me how to retrieve it. Please help me. And how to make plist in my project itself.
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一抹微笑 2024-11-07 00:03:58

快速的方法是:

NSString *myText = [NSString stringWithContentsOfFile:filePath
                            encoding: NSUTF8StringEncoding
                            error: NULL];

不要忘记进行错误处理。

请注意,这将阻塞主线程,直到加载整个文本文件。如果您正在处理大文件,您可能需要使用 mmapmunmap

顺便说一句,如果您想通过网络加载文本文件,永远不要使用NSString stringWithContentsOfURL(或任何一般的 *WithContentsOfURL 方法)。此方法将阻塞主线程,直到文件下载完毕。在这种情况下,请改用 NSURLConnectionASIHTTPRequest

The quick way would be:

NSString *myText = [NSString stringWithContentsOfFile:filePath
                            encoding: NSUTF8StringEncoding
                            error: NULL];

Don't forget to do your error handling.

Be aware that this will block the main thread until the whole text file has been loaded. If you're dealing with large files, you may want to use mmap and munmap.

As a side note, if you'll ever want to load a text file over a network, never use NSString stringWithContentsOfURL (or any of the *WithContentsOfURL methods in general). This method will block the main thread until the file has been downloaded. In that case, use NSURLConnection or ASIHTTPRequest instead.

榆西 2024-11-07 00:03:58

您可以尝试使用 NSString 类方法 stringWithContentsOfFile:

You can try using NSString class method stringWithContentsOfFile:

醉生梦死 2024-11-07 00:03:58

我想,您可能想知道,如何在应用程序中处理 plist ...

这是从 plist 获取数据并写入 plist 的 SO 帖子...

如何读取 plist 数据并从中获取 int?

如何将数据写入plist

这是从中读取字典中数据的代码列表...

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *myplistPath = [path stringbyAppendingPathComponent:@"myplist.plist"];

NSDictionary *myDictionary = [[NSDictionary alloc] initWithContentsOfFile:myplist];

I think , you might want to know, how to deal with plist in application ...

Here is the SO post to get data from plist and to write to plist ...

How to read a plist data and get int from it?

How to write the data to the plist

Here is the Code to read the data in dictionary from plist...

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *myplistPath = [path stringbyAppendingPathComponent:@"myplist.plist"];

NSDictionary *myDictionary = [[NSDictionary alloc] initWithContentsOfFile:myplist];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文