首頁  >  文章  >  後端開發  >  为什么fwrite以后,fread不出来东西呢

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

WBOY
WBOY原創
2016-06-13 12:52:081087瀏覽

为何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一般都涉及缓冲,两次操作中间无间断总会有想象不到的问题……
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn