file-io

How to fopen() on the iPhone?

…衆ロ難τιáo~ 提交于 2020-01-09 13:04:28
问题 The iPhone SDK docs claim fopen() is a supported method of file access but I am unable to get it to return a FILE handle. I am accessing a directory which is included in my project. I have tried fopen "filename","dir/filename","./filename","./dir/filename","/dir/filename" all returning with a null pointer. Some people report using it with no issue so I am sure it is something simple! 回答1: if you're trying to access a file within your application bundle, you need to get the full path to it: [

Reading/Writing a structure into a binary file

风格不统一 提交于 2020-01-09 10:14:33
问题 I am running a program with 3 structures and what I am doing to read/write in the binary file is the following: struct Medico { int Id_Doctor; int Estado; char Nombre[60]; char Clave_Acceso[20]; char Especialidad[40]; struct Medico *next; }; typedef struct Medico *Medicazos; typedef struct Medico Meds; Medicazos Nuevo; FILE *Archivaldo; char especialida[40], password[20]; char nombre_doc[60]; int estado_doc, id_doc; Archivaldo=fopen("md.dat", "rb"); fclose(Archivaldo); if((Archivaldo=fopen(

Reading/Writing a structure into a binary file

旧巷老猫 提交于 2020-01-09 10:13:18
问题 I am running a program with 3 structures and what I am doing to read/write in the binary file is the following: struct Medico { int Id_Doctor; int Estado; char Nombre[60]; char Clave_Acceso[20]; char Especialidad[40]; struct Medico *next; }; typedef struct Medico *Medicazos; typedef struct Medico Meds; Medicazos Nuevo; FILE *Archivaldo; char especialida[40], password[20]; char nombre_doc[60]; int estado_doc, id_doc; Archivaldo=fopen("md.dat", "rb"); fclose(Archivaldo); if((Archivaldo=fopen(

fclose return value check

こ雲淡風輕ζ 提交于 2020-01-09 09:42:54
问题 Is it required to check the return value of fclose? If we have successfully opened a file, what are the chances that it may fail to close? Thanks! Regards, Jay 回答1: When you fwrite to a file, it may not actually write anything, it may stay in a buffer (inside the FILE object). Calling fflush would actually write it to disk. That operation may fail , for example if you just ran out of disk space, or there is some other I/O error. fclose flushes the buffers implicitly too, so it may fail for

Is there a way in Matlab to determine the number of lines in a file without looping through each line?

我与影子孤独终老i 提交于 2020-01-09 06:20:55
问题 Obviously one could loop through a file using fgetl or similar function and increment a counter, but is there a way to determine the number of lines in a file without doing such a loop? 回答1: I like to use the following code for exactly this task fid = fopen('someTextFile.txt', 'rb'); %# Get file size. fseek(fid, 0, 'eof'); fileSize = ftell(fid); frewind(fid); %# Read the whole file. data = fread(fid, fileSize, 'uint8'); %# Count number of line-feeds and increase by one. numLines = sum(data ==

How to read tokens without reading whole line or file

我与影子孤独终老i 提交于 2020-01-09 03:53:08
问题 Is there a well-hidden way to read tokens from a file or file-like object without reading entire lines? The application I immediately have (someone else's problem, not mine) is transposing a large matrix with a few very long rows, essentially performing an itertools.izip() on iterators that pick out the elements of a single column. The idea is not not have the entire file in memory during iteration. The rows are space-delimited ASCII decimal numbers. The problem would be simple with Java's

can I check if a file exists at a URL?

蓝咒 提交于 2020-01-09 02:13:45
问题 I know I can locally, on my filesystem, check if a file exists: if(File.Exists(path)) Can I check at a particular remote URL? 回答1: If you're attempting to verify the existence of a web resource, I would recommend using the HttpWebRequest class. This will allow you to send a HEAD request to the URL in question. Only the response headers will be returned, even if the resource exists. var url = "http://www.domain.com/image.png"; HttpWebResponse response = null; var request = (HttpWebRequest

HTML input type=file, get the image before submitting the form

我怕爱的太早我们不能终老 提交于 2020-01-08 16:02:14
问题 I'm building a basic social network and in the registration the user uploads a display image. Basically I wanted to display the image, like a preview on the same page as the form, just after they select it and before the form is submitted. Is this possible? 回答1: Here is the complete example for previewing image before it gets upload. HTML : <html> <head> <link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />

How to read a text file from server using JavaScript?

北城以北 提交于 2020-01-08 12:59:05
问题 On the server, there is a text file. Using JavaScript on the client, I want to be able to read this file and process it. The format of the file on the server cannot be changed. How can I get the contents of the file into JavaScript variables, so I can do this processing? The size of the file can be up to 3.5 MB, but it could easily be processed in chunks of, say, 100 lines (1 line is 50-100 chars). None of the contents of the file should be visible to the user; he will see the results of the

Difference between parsing a text file in r and rb mode

倾然丶 夕夏残阳落幕 提交于 2020-01-08 11:47:09
问题 What makes parsing a text file in 'r' mode more convenient than parsing it in 'rb' mode? Especially when the text file in question may contain non-ASCII characters. 回答1: This depends a little bit on what version of Python you're using. In Python 2, Chris Drappier's answer applies. In Python 3, its a different (and more consistent) story: in text mode ( 'r' ), Python will parse the file according to the text encoding you give it (or, if you don't give one, a platform-dependent default), and