查找从服务器收到的NSData的文件类型 [英] Finding file type of NSData recieved from server

查看:122
本文介绍了查找从服务器收到的NSData的文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过TCP / IP从套接字接收文本文件。由于数据是以字节形式接收的,因此没有文件扩展名(或文件名)。我可以从中获取数据(以NSData的形式)并将其加载到UITextView中并显示它。

I am receiving a text file from a socket over TCP/IP. There is no file extension (or filename for that matter) as the data is received as bytes. I can take the data from this (in the form of NSData) and load it into a UITextView and display it fine.

我想将此数据保存到文件中。但是,我不知道数据的格式是什么(txt,rtf,doc,docx)?我把它假设为.txt并将其保存在文档目录中,但有没有一种编程方式可以找到它?我查看了StackOverflow并在文档中找不到任何内容。

I want to persist this data to a file. However, I don't know what format the data is in (txt, rtf, doc, docx)? I assume it as .txt and save it in the documents directory, but is there a programmatic way of finding out for sure? I've looked around StackOverflow and at the documentation and haven't been able to find anything.

有没有办法获取文件属性的详细信息,如文件创建日期。

And is there a way to get the details of the file attributes like the file creation date.

提前致谢。

推荐答案

当你通过TCP / IP连接发送文件,只有文件内容将转换为数据并传递。如果您需要文件名,扩展名和文件属性,则必须单独添加这些详细信息并将其附加到要发送的数据中。然后你可以在接收端解析它并使用你的应用程序内的结果。

When you send a file over a TCP/IP connection, only the file contents will be converted to data and be passed across. If you want the filename,extension and the file attributes, then you will have to add those details separately and append it with the data to be sent. Then you can parse it at the receiver end and use the results inside your app.

这篇关于查找从服务器收到的NSData的文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆