Finding file type of NSData recieved from server

只谈情不闲聊 提交于 2019-12-21 21:50:38

问题


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.

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.

Thanks in advance.


回答1:


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.




回答2:


You can choose the file type you want when you save the data, you can get attributes from file,please refer to Get file creation date.



来源:https://stackoverflow.com/questions/26751051/finding-file-type-of-nsdata-recieved-from-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!