2

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.

Abi
  • 128
  • 1
  • 7

2 Answers2

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.

abi
  • 819
  • 2
  • 9
  • 24
0

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.

Community
  • 1
  • 1
gabbler
  • 13,626
  • 4
  • 32
  • 44
  • I want the original creation date of the file that is received from the server. By using this we can get the creation date of the file we created inside the app. – Abi Nov 05 '14 at 06:56
  • So what you want to do is to get file attributes of the file server sent to you? – gabbler Nov 05 '14 at 07:00
  • It looks like what you get now is the file content, does server send you the file attributes? Which can be the first few bytes. Once you get it, you can save it somewhere with the key is the file name. – gabbler Nov 05 '14 at 09:12
  • Yes, what I get now is the file content. So if I need to get the file attributes from the server, then it should be included with the data sent from the server, right? So does that mean there is no way to find out the type of file being sent by any other means? – Abi Nov 05 '14 at 09:30
  • Yes,I don't think so, because you only get the content. – gabbler Nov 05 '14 at 09:33