>  기사  >  백엔드 개발  >  为什么fwrite以后,fread不出来东西呢

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

WBOY
WBOY원래의
2016-06-13 12:52:081088검색

为何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으로 문의하세요.