Maison  >  Article  >  développement back-end  >  为什么fwrite以后,fread不出来东西呢

为什么fwrite以后,fread不出来东西呢

WBOY
WBOYoriginal
2016-06-13 12:52:081088parcourir

为何fwrite以后,fread不出来东西呢。
$file = 'test.txt';
$fileHandle = fopen($file,'w+');
fwrite($fileHandle, 'Newly inserted text');
$fileContents = fread($fileHandle, filesize($file));
echo $fileContents;
fclose($fileHandle);

The manual says that if the w+ option is specified then the file is opened for reading and writing. From what I understand this means that I should be able to read from the file after writing to it. But the code above displays nothing after writing to the file. The file is chmodded 777.  Can someone please explain to me why this is so :D

同问,为啥呢。
以w+模式打开,应该是可读,
可为何fwrite以后,fread不出来东西呢。


------解决方案--------------------
还真没试过这样,但可以猜想一下
1.指针问题
2.IO问题

想想写完之后指针在哪?如果在文件开头,第二次写入不是写到第一次前面了?
文件IO一般都涉及缓冲,两次操作中间无间断总会有想象不到的问题……
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn