{"id":266297,"date":"2023-03-05T14:06:34","date_gmt":"2023-03-05T06:06:34","guid":{"rendered":"https:\/\/lrxjmw.cn\/qzdicztgtydj.html"},"modified":"2023-03-05T14:06:34","modified_gmt":"2023-03-05T06:06:34","slug":"qzdicztgtydj","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/qzdicztgtydj.html","title":{"rendered":"QT\u4e2d\u7684IO\u64cd\u4f5c\u901a\u8fc7\u7edf\u4e00\u7684\u63a5\u53e3\u7b80\u5316\u4e86\u6587\u4ef6\u4e0e\u5916\u90e8\u8bbe\u5907\u7684\u64cd\u4f5c\u65b9\u5f0f"},"content":{"rendered":"
\u7b80\u4ecb<\/p>\n
QT\u4e2d\u7684IO\u64cd\u4f5c\u901a\u8fc7\u7edf\u4e00\u7684\u63d2\u53e3\u7b80\u5316\u4e86\u6587\u4ef6\u4e0e\u5916\u90e8\u8bbe\u5907\u7684\u64cd\u4f5c\u65b9\u6cd5\uff0cQT\u4e2d\u6587\u4ef6\u88ab\u5f53\u6210\u4e00\u79cd\u7279\u6b8a\u7684\u5916\u90e8\u8bbe\u5907\uff0c\u6587\u4ef6\u64cd\u4f5c\u4e0e\u5916\u90e8\u8bbe\u5907\u64cd\u4f5c\u76f8\u540c\u3002IO\u64cd\u4f5c\u7684\u672c\u8d28\u662f\u8fde\u7eed\u50a8\u5b58\u7a7a\u95f4\u7684\u6570\u636e\u8bfb\u5199\u3002<\/p>\n
1.IO\u8bbe\u5907\u7684\u7c7b\u578b<\/p>\n
\u6b21\u5e8f\u5b58\u53d6\u8bbe\u5907\uff1a\u53ea\u80fd\u4ece\u5934\u5f00\u59cb\u6b21\u5e8f\u8bfb\u5199\u6570\u636e\uff0c\u4e0d\u80fd\u6307\u5b9a\u6570\u636e\u7684\u8bfb\u5199\u4f4d\u7f6e<\/p>\n
\u968f\u673a\u5b58\u53d6\u8bbe\u5907\uff1a\u53ef\u4ee5\u5b9a\u4f4d\u5230\u4efb\u610f\u4f4d\u7f6e\u8fdb\u884c\u6570\u636e\u7684\u8bfb\u5199<\/p>\n
<\/p>\n
2.QFile<\/p>\n
\u5728Qt\u5e2e\u52a9\u6587\u6863\u4e0a\u9762\uff0c\u5018\u82e5\u76f4\u63a5\u67e5\u8be2QFile\u5e2e\u52a9\u6587\u6863\uff0c\u770b\u4e0d\u5230\u51e0\u4e2a\u5173\u4e8e\u6587\u4ef6\u8bfb\u5199\u7684\u51fd\u6570\uff0c\u7531\u4e8eQt\u5c06\u8bfb\u5199\u64cd\u4f5c\u90fd\u5c01\u88c5\u5728\u6cdb\u578bQIODevice\u4e0a\u9762\uff1a<\/p>\n
QIODevice\u7c7b\u662f\u5bf9\u8f93\u5165\u8f93\u5165\u8bbe\u5907\u7684\u5177\u8c61\u5efa\u6a21\uff0c\u6d89\u53ca\u5230\u8bfb\u5199\u7684\u6587\u4ef6\u7c7bQFile\u3001\u7f51\u7edc\u6536\u53d1QTcpSocket\/QUdpSocket\u3001\u8fdb\u7a0b\u8f93\u5165\u8f93\u51faQProcess\uff0c\u90fd\u662f\u4eceQIODevice\u7c7b\u6d3e\u751f\u7684\u3002QIODevice\u662f\u5341\u5206\u91cd\u8981\u7684\u5b50\u7c7b\uff0c\u4e4b\u540e\u63d0\u5230\u7f51\u8def\u6536\u53d1\u548c\u8fdb\u7a0b\u7c7b\u65f6\u5c31\u4f1a\u518d\u8bb2\uff0c\u672c\u8282\u4e3b\u8981\u5173\u6ce8\u4e0e\u6587\u4ef6\u8bfb\u5199\u76f8\u5173\u7684\u63d2\u53e3\u51fd\u6570\u3002<\/p>\n
QFileDevice\u662f\u5bf9\u6587\u4ef6\u8bbe\u5907\u7684\u5177\u8c61\uff0c\u867d\u7136\u5728Unix\u548cLinux<\/a>\u7cfb\u7edf<\/a>\u4e2d\u6240\u6709\u4e1c\u897f\u90fd\u662f\u6587\u4ef6\u8bbe\u5907\uff0c\u5c31\u8fde\u786c\u4ef6\u8bbe\u5907\u4e5f\u5177\u8c61\u6210\u6587\u4ef6\u8bbe\u5907\uff0c\u4f8b\u5982\/dev\/usb0\u662f\u4ee3\u8868USB\u8bbe\u5907\u7684\u6587\u4ef6\uff0cQFileDevice\u5c31\u662f\u63cf\u8ff0\u6587\u4ef6\u8bbe\u5907\u7684\u7c7b\uff0cQFileDevice\u8fd9\u4e00\u5c42\u6cdb\u578b\u7684\u63d2\u53e3\u51fd\u6570\u6bd4\u8f83\u5c11\uff0c\u53ef\u4ee5\u4e0d\u7528\u7ba1\u7684\u3002<\/p>\n QFile\u7c7b\u5c31\u662f\u672c\u8282\u7684\u5b66\u4e60\u91cd\u70b9\uff0c\u6b64\u540e\u6e10\u6e10\u8bb2\u89e3\u3002\u4e00\u9f50\u4eceQFileDevice\u6d3e\u751f\u7684\u8fd8\u6709\u4e2aQSaveFile\uff0c\u8fd9\u4e2a\u4fdd\u5b58\u6587\u4ef6\u7c7b\uff0c\u5c31\u4e3a\u4e86\u5b89\u5168\u5730\u4fdd\u5b58\u6587\u4ef6\u800c\u8bbe\u8ba1\u7684\uff0c\u7531\u4e8e\u7a0b\u5e8f\u8fd0\u884c\u65f6\u53ef\u80fd\u6709bug\u9020\u6210\u5d29\u6e83\uff0c\u5047\u5982\u5d29\u6e83\u65f6\u6b63\u5728\u5199\u5165\u6587\u4ef6\uff0c\u8fd9\u4e48\u6587\u4ef6\u88ab\u6539\u5199\u4e86\u4e00\u90e8\u4efd\uff0c\u4f46\u53c8\u6ca1\u66f4\u6539\u5b8c\u5168\uff0c\u4f1a\u9020\u6210\u539f\u59cb\u6587\u4ef6\u7684\u6bc1\u574f\u3002QSaveFile\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u6587\u4ef6\u7684\u4e0d\u5b89\u5168\u8bfb\u5199\uff0c\u9632\u6b62\u51fa\u73b0\u534a\u540a\u5b50\u95ee\u9898\uff0cQSaveFile\u6709\u4e24\u4e2a\u91cd\u8981\u51fd\u6570\uff1acancelWriting()\u51fd\u6570\u53d6\u6d88\u5199\u5165\u64cd\u4f5c\uff0ccommit()\u9012\u4ea4\u6240\u6709\u5199\u5165\u64cd\u4f5c\uff0c\u6653\u5f97QSaveFile\u6709\u8fd9\u4e24\u4e2a\u51fd\u6570\u5c31\u5dee\u4e0d\u591a\u4e86\uff0c\u7531\u4e8e\u4e5f\u6ca1\u5176\u4ed6\u91cd\u8981\u529f\u80fd\u3002QSaveFile\u7c7b\u4e0d\u5355\u72ec\u8bb2\u4e86\uff0c\u7531\u4e8e\u5c31\u90a3\u4e24\u4e2a\u91cd\u8981\u51fd\u6570\u800c\u5df2\u3002\u4e0b\u8fb9\u5f00\u59cb\u5b66\u4e60QFile\u7c7b\u3002<\/p>\n <\/p>\n \u3010\u9886\u66f4\u591aQT\u5b66\u4e60\u8d44\u6599\uff0c\u70b9\u51fb\u4e0b\u65b9\u94fe\u63a5\u514d\u8d39\u53d1\u653e\u2193\u2193\uff0c\u5148\u7801\u4f4f\u4e0d\u8d70\u5931~\u3011<\/p>\n \u70b9\u51fb\u2192\u9886\u53d6\u300c\u94fe\u63a5\u300d<\/p>\n 2.1QFile\u529f\u80fd\u51fd\u6570<\/p>\n \u5728\u591a\u6570\u60c5\u51b5\u4e0b\uff0cQFile\u90fd\u662f\u914d\u5408QTextStream\u548cQDataStream\u4f7f\u7528\uff0c\u5176\u5b9e\u4e5f\u53ef\u4ee5\u4f7f\u7528QFile\u81ea\u5e26\u7684\u8bfb\u5199\u51fd\u6570\u5904\u7406\u6587\u4ef6\u3002QFile\u9664\u4e86\u9002\u5b9c\u4e8e\u666e\u901a\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u5e76\u4e14\u5bf9Qt\u7a0b\u5e8f\u5185\u5d4c\u7684\u8d44\u6e90\u6587\u4ef6\u4e5f\u662f\u901a\u7528\u7684\uff0c\u533a\u522b\u53ea\u662f\u5185\u5d4c\u8d44\u6e90\u6587\u4ef6\u5168\u662f\u53ea\u8bfb\u7684\u3002\u4e0b\u8fb9\u5927\u81f4\u5206\u51e0\u5757\u6765\u4ecb\u7ecdQFile\u7684\u529f\u80fd\u51fd\u6570\uff1a<\/p>\n \uff081\uff09\u6784\u9020\u51fd\u6570\u548c\u6253\u5f00\u51fd\u6570<\/p>\n QFile\u4e00\u822c\u5728\u6784\u9020\u51fd\u6570\u91cc\u6307\u5b9a\u987b\u8981\u6253\u5f00\u7684\u6587\u4ef6\u540d\uff1a<\/p>\n \n \u53c2\u6570name\u5c31\u662f\u987b\u8981\u6253\u5f00\u7684\u6587\u4ef6\u540d\uff0c\u6ce8\u610f\u5fc5\u987b\u662f\u5b9e\u9645\u7684\u6587\u4ef6\u8def\u5f84\uff0c\u4e0d\u80fd\u662f\u53ea\u6709\u6587\u4ef6\u5939\u8def\u5f84\u3002parent\u662f\u7236\u5bf9\u8c61\u8868\u9488\u3002\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u6ca1\u6709\u6307\u5b9a\u6587\u4ef6\u540d\uff0c\u5fc5\u987b\u5728\u4ee5\u540e\u7684\u4ee3\u7801\u91cc\u7528\u5982\u4e0b\u51fd\u6570\u8bbe\u7f6e\u6587\u4ef6\u540d\uff1a<\/p>\n \n \u8bbe\u7f6e\u4e86\u6587\u4ef6\u540d\u4ee5\u540e\u624d\u4f1a\u6253\u5f00\u6587\u4ef6\u8fdb\u884c\u8bfb\u5199\u3002\u83b7\u53d6\u6587\u4ef6\u540d\u5c31\u7528fileName()\u51fd\u6570\uff0c\u4e0d\u5355\u72ec\u5217\u4e86\u3002<\/p>\n \u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u6a21\u5f0f\u6253\u5f00\u6587\u4ef6\uff0c\u4f8b\u5982\u53ea\u8bfb\u6a21\u5f0f\u3001\u53ea\u5199\u6a21\u5f0f\u3001\u8bfb\u5199\u6a21\u5f0f\u7b49\uff0c\u6700\u5e38\u7528\u7684\u6253\u5f00\u51fd\u6570\u4e3a\uff1a<\/p>\n \n OpenMode\u679a\u4e3e\u7c7b\u578b\u662f\u5728\u6cdb\u578bQIODevice\u5b9a\u4e49\u7684\uff0c\u6709\u5982\u4e0b\u6253\u5f00\u6a21\u5f0f\uff1a<\/p>\n OpenMode\u679a\u4e3e\u5e38\u91cf<\/p>\n \u6570\u503c<\/p>\n \u63cf\u8ff0<\/p>\n QIODevice::NotOpen<\/p>\n 0x0000<\/p>\n \u7528\u4e8e\u8868\u793a\u8bbe\u5907\u6216\u6587\u4ef6\u4ecd\u672a\u6253\u5f00\u3002<\/p>\n QIODevice::ReadOnly<\/p>\n 0x0001<\/p>\n \u6309\u8bfb\u53d6\u6a21\u5f0f\u6253\u5f00\u3002<\/p>\n QIODevice::WriteOnly<\/p>\n 0x0002<\/p>\n \u6309\u5199\u5165\u6a21\u5f0f\u6253\u5f00\uff0c\u6ce8\u610f\u5355\u72ec\u7528\u8fd9\u4e2a\u6a21\u5f0f\u4f1a\u53c2\u6742Truncate\u3002<\/p>\n QIODevice::ReadWrite<\/p>\n ReadOnly|WriteOnly<\/p>\n \u6309\u8bfb\u53d6\u548c\u5199\u5165\u6a21\u5f0f\u6253\u5f00\uff0c\u65e2\u80fd\u8bfb\u4e5f\u80fd\u5199\u3002<\/p>\n QIODevice::Append<\/p>\n 0x0004<\/p>\n \u6309\u8ffd\u52a0\u6a21\u5f0f\u6253\u5f00\uff0c\u6587\u4ef6\u5148\u524d\u5b58\u5728\u7684\u5185\u5bb9\u4e0d\u4f1a\u88ab\u8986\u76d6\uff0c\u65b0\u6570\u636e\u4ece\u6587\u4ef6\u672b\u5c3e\u5f00\u59cb\u5199\u5165\u3002<\/p>\n QIODevice::Truncate<\/p>\n 0x0008<\/p>\n \u5f3a\u5236\u6e05\u7a7a\u6587\u4ef6\u91cc\u66fe\u7ecf\u5b58\u7684\u65e7\u6570\u636e\uff0c\u65b0\u6570\u636e\u4ece\u96f6\u5f00\u59cb\u5199\u5165\u3002<\/p>\n QIODevice::Text<\/p>\n 0x0010<\/p>\n \u5728\u8bfb\u53d6\u65f6\uff0c\u628a\u884c\u5c3e\u7ed3\u675f\u7b26\u66f4\u6539\u4e3a'n'\uff1b\u5728\u5199\u5165\u65f6\uff0c\u628a\u884c\u5c3e\u7ed3\u675f\u7b26\u66f4\u6539\u4e3a\u672c\u5730\u7cfb\u7edf\u6362\u884c\u98ce\u683c\uff0c\u4f8b\u5982Windows\u6587\u672c\u6362\u884c\u662f\"rn\"<\/p>\n QIODevice::Unbuffered<\/p>\n 0x0020<\/p>\n \u5ffd\u89c6\u7f13\u51b2\u533a\uff0c\u76f4\u63a5\u8bfb\u5199\u8bbe\u5907\u6216\u6587\u4ef6\u3002\u9664\u975e\u662f\u5b9e\u65f6\u6027\u5f88\u5f3a\u7684\u7a0b\u5e8f\uff0c\u5426\u5219\u7528\u4e0d\u5230\u3002<\/p>\n \u6587\u4ef6\u8bfb\u53d6\u65f6\uff0c\u5e38\u89c1\u7ec4\u5408\u5982\u4e0b\u8fb9\u4e24\u53e5\uff1a<\/p>\n \n \u6ce8\u610f\u4ee5QIODevice::Text\u6a21\u5f0f\u6253\u5f00\u6587\u4ef6\u65f6\uff0c\u8bfb\u5199\u7684\u6570\u636e\u4e0d\u4e00\u5b9a\u662f\u539f\u59cb\u6570\u636e\uff0c\u7531\u4e8eQFile\u624b\u52a8\u628a\u6362\u884c\u7b26\u505a\u4e86\u8f6c\u6362\uff0c\u8bfb\u53d6\u5f97\u5230\u7684\u7f13\u51b2\u533a\u6570\u636e\u4e0e\u539f\u59cb\u6587\u4ef6\u662f\u53ef\u80fd\u4e0d\u4e00\u6837\u7684\uff0c\u4f8b\u5982Windows\u6587\u672c\uff0c\u6362\u884c\u7b26\u662f\"rn\"\u4e24\u4e2a\u5b57\u7b26\uff0c\u7528QIODevice::Text\u8bfb\u53d6\u65f6\u53ea\u4f1a\u542c\u5230'n'\u4e00\u4e2a\u5b57\u7b26\uff1b\u5199\u5165\u65f6\u5c31\u53cd\u8fc7\u6765\uff0c\u4ee3\u7801\u5199\u5165\u4e00\u4e2a'n'\uff0c\u5b9e\u9645\u6587\u4ef6\u5c31\u662f\u4e24\u4e2a\u8fde\u7eed\u5b57\u7b26\"rn\"\uff0c\u6240\u4ee5\u8981\u6ce8\u610fQIODevice::Text\u6a21\u5f0f\u8bfb\u5199\u7684\u4e0d\u4e00\u5b9a\u662f\u539f\u59cb\u6570\u636e\u3002<\/p>\n \u5bf9\u4e8e\u6587\u4ef6\u5199\u5165\u65f6\uff0c\u5176\u5e38\u7528\u6253\u5f00\u6a21\u5f0f\u5982\u4e0b\uff1a<\/p>\n \n \u5047\u5982\u6587\u4ef6\u6253\u5f00\u65f6\u65e2\u8981\u8bfb\uff0c\u53c8\u8981\u5199\uff0c\u8fd9\u4e48\u5efa\u8bae\u7528\u5982\u4e0b\u6a21\u5f0f\uff1a<\/p>\n \n \u6587\u4ef6\u6253\u5f00\u4ee5\u540e\uff0c\u53ef\u4ee5\u7528\u4eceQIODevice\u627f\u7ee7\u6765\u7684\u8bfb\u5199\u51fd\u6570\u64cd\u4f5c\u6587\u4ef6\uff0c\u6216\u5219\u7528QFile\u5bf9\u8c61\u8868\u9488\u6784\u9020QTextStream\u6216QDataStream\u6765\u8bfb\u5199\u6587\u4ef6\u3002<\/p>\n \u4e0d\u4ec5\u91cc\u9762\u6700\u5e38\u7528\u7684\u6253\u5f00\u51fd\u6570\uff0c\u53e6\u5916\u8fd8\u6709\u4e24\u4e2a\u4e0d\u592a\u5e38\u7528\u7684\u6253\u5f00\u51fd\u6570\uff1a<\/p>\n \n \u91cc\u9762\u7b2c\u4e00\u4e2a\u4e0d\u5e38\u7528\u6253\u5f00\u51fd\u6570\u53ef\u4ee5\u6253\u5f00\u6807\u51c6\u8f93\u5165\u6d41stdin\u3001\u6807\u51c6\u8f93\u51fa\u6d41stdout\u3001\u6807\u51c6\u9519\u8bef\u6d41stderr\uff0c\u6216\u5219\u5176\u4ed6\u6587\u4ef6\u53e5\u67c4\uff08Windows\u7cfb\u7edf\u4e2d\u53c2\u6570\u91cc\u7684fh\u53e5\u67c4\u5fc5\u987b\u4ee5\u4e8c\u8865\u7801\u6a21\u5f0f\u6253\u5f00\uff0c\u6253\u5f00\u53e5\u67c4\u65f6\u8981\u5e26'b'\u6a21\u5f0f\uff09\u3002\u6700\u540e\u7684\u53c2\u6570handleFlags\u901a\u5e38\u5c31\u7528\u4e0d\u5173\u6389\u7684DontCloseHandle\u5c31\u53ef\u4ee5\u4e86\uff0c\u82e5\u679c\u5e0c\u671bQFile\u5bf9\u8c61\u6790\u6784\u65f6\u624b\u52a8\u5173\u6389\u6587\u4ef6\u6216\u6d41\uff0c\u8fd9\u4e48\u53ef\u4ee5\u7528QFileDevice::AutoCloseHandle\u3002<\/p>\n \u5bf9\u4e8eWindows\u5e73\u53f0\uff0c\u5047\u5982\u5e0c\u671b\u5728\u56fe\u5f62\u754c\u9762\u7a0b\u5e8f\u4e0a\u9762\u7528\u6807\u51c6\u7684\u8f93\u5165\u8f93\u51fa\u548c\u9519\u8bef\u6d41\uff0c\u8fd9\u4e48\u5fc5\u987b\u5728\u9879\u76ee\u6587\u4ef6\u52a0\u4e00\u53e5\uff1a<\/p>\n CONFIG+=console<\/p>\n \u91cc\u9762\u7b2c\u4e8c\u4e2a\u4e0d\u5e38\u7528open()\u51fd\u6570\u662f\u4ee5fd\u6587\u4ef6\u63cf\u8ff0\u7b26\u53c2\u6570\uff0c\u4e0eC\u8bed\u8a00\u4e0a\u9762\u7684\u6587\u4ef6\u8bfb\u5199\u7528\u5230\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u7c7b\u4f3c\uff0c\u5047\u5982fd\u4e3a0\u662f\u6807\u51c6\u8f93\u5165\u6d41\uff0c\u4e3a1\u662f\u6807\u51c6\u8f93\u51fa\u6d41\uff0c\u4e3a2\u662f\u6807\u51c6\u9519\u8bef\u6d41\u3002<\/p>\n open()\u51fd\u6570\u6253\u5f00\u6b63\u786e\u5c31\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defasle\uff0c\u6ce8\u610f\u5224\u5b9a\u8be5\u51fd\u6570\u7684\u8fd4\u56de\u503c\uff0c\u4e4b\u540e\u518d\u8fdb\u884c\u6587\u4ef6\u8bfb\u5199\u64cd\u4f5c\uff01<\/p>\n \uff082\uff09\u8bfb\u5199\u51fd\u6570<\/p>\n \u672c\u5c0f\u8282\u4e3b\u8981\u4ecb\u7ecd\u4eceQIODevice\u627f\u7ee7\u800c\u81f3\u7684\u8bfb\u5199\u51fd\u6570\uff0c\u8fd9\u79cd\u51fd\u6570\u8981\u5728QIODevice\u7c7b\u5e2e\u52a9\u6587\u6863\u624d\u4f1a\u627e\u5230\u3002<\/p>\n \u9996\u5148\u662f\u7b80\u5355\u7684\u5b57\u8282\u8bfb\u5199\u51fd\u6570\uff1a<\/p>\n \n \u53c2\u6570\u8868\u9488c\u5c31\u662f\u8bfb\u53d6\u7684\u4e00\u4e2a\u5b57\u8282\u5373\u5c06\u5b58\u5230\u7684\u53d8\u91cf\u8868\u9488\uff0c\u7a0b\u5e8f\u5458\u987b\u8981\u81ea\u5df1\u5148\u5b9a\u4e49\u4e00\u4e2achar\u53d8\u91cf\uff0c\u628a\u8fd9\u4e2a\u53d8\u91cf\u5730\u5740\u4f20\u9012\u7ed9\u200bgetChar()\u51fd\u6570\uff0c\u5047\u82e5\u8bfb\u53d6\u4e00\u5b57\u8282\u6210\u529f\u5c31\u8fd4\u56detrue\uff1b\u5047\u5982\u4e4b\u524d\u65e9\u5df2\u5230\u4e86\u6587\u4ef6\u672b\u5c3e\uff0c\u6ca1\u6709\u5b57\u8282\u53ef\u4ee5\u8bfb\u4e86\uff0c\u5c31\u8fd4\u56defalse\u3002\u200bgetChar()\u51fd\u6570\u6709\u4e00\u4e2a\u9006\u64cd\u4f5c\u51fd\u6570\uff1a<\/p>\n \n \u8fd9\u4e2a\u51fd\u6570\u5c31\u662f\u628a\u4e4b\u524d\u8bfb\u53d6\u7684\u5b57\u8282c\uff08\u6b64\u6b21\u662f\u53d8\u91cf\uff0c\u4e0d\u662f\u8868\u9488\uff09\u653e\u56de\u5bb6\uff0c\u4f46\u662f\u5f53\u524d\u8bfb\u53d6\u6e38\u6807\u51cf\u4e00\uff0c\u8fd8\u539f\u5230\u8bfb\u53d6\u4e4b\u524d\u72b6\u6001\u3002\u6ce8\u610f\uff0c\u5047\u82e5c\u5b57\u8282\u4e0d\u7b49\u4e8e\u4e4b\u524d\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u503c\uff0c\u8fd9\u4e48\u200bungetChar()\u51fd\u6570\u64cd\u4f5c\u7ed3\u679c\u672a\u80fd\u9884\u77e5\uff0c\u6240\u4ee5\u4e0d\u8981\u4f7f\u7528\u200bungetChar()\u51fd\u6570\u66f4\u6539\u6587\u4ef6\uff01<\/p>\n \u5199\u5165\u4e00\u4e2a\u5b57\u8282\u5230\u6587\u4ef6\u4e2d\uff0c\u5e94\u5f53\u4f7f\u7528\u51fd\u6570\uff1a<\/p>\n \n \u8fd9\u4e2a\u51fd\u6570\u4f1a\u628a\u5b57\u8282c\u5199\u5165\u6587\u4ef6\uff0c\u5e76\u5c06\u6587\u4ef6\u6e38\u6807\u52a0\u4e00\u3002<\/p>\n \u8fd9\u513f\u6211\u4eec\u4e13\u95e8\u8bb2\u4e00\u4e0b\u6587\u4ef6\u6e38\u6807\uff0c\u6587\u4ef6\u5728\u8bfb\u5199\u65f6\uff0c\u5171\u540c\u4f7f\u7528\u4e00\u4e2a\u60df\u4e00\u7684\u6e38\u6807\uff08QFile\u5185\u90e8\u6709\uff09\uff0c\u6211\u4eec\u8fd9\u513f\u968f\u610f\u53d6\u4e2a\u540d\u5b50\u53ebpos\uff08Position\uff09\uff0c\u8fd9\u4e2apos\u5728\u6587\u4ef6\u521a\u6253\u5f00\u65f6\u901a\u5e38\u5904\u4e8e\u6587\u4ef6\u5f00\u5934\u4f4d\u7f6e\uff1a<\/p>\n <\/p>\n \u8bf4\u660e\u4e00\u4e0b\uff0c\u6587\u4ef6\u7684\u5927\u5c0f\u662f\u7528size()\u51fd\u6570\u83b7\u53d6\u7684\uff1a<\/p>\n \n \u6587\u4ef6\u5927\u5c0f\u4f7f\u7528qint64\u7c7b\u578b\u53d8\u91cf\u4fdd\u5b58\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4QFile\u6700\u5927\u652f\u63012^63-1==9,223,372,036,854,775,807\u5b57\u8282\u7684\u6587\u4ef6\uff0c\u6240\u4ee5\u4e0d\u7528\u64cd\u52b3QFile\u5bf9\u5927\u6587\u4ef6\u7684\u652f\u6301\u7279\u70b9\u3002<\/p>\n QFile\u5f53\u524d\u6e38\u6807\u53ef\u4ee5\u7528\u51fd\u6570\u83b7\u53d6\uff1a<\/p>\n \n \u5bf9\u4e8e\u6309\u5b57\u8282\u8bfb\u53d6\u7684\u51fd\u6570\u200bgetChar()\uff0c\u6bcf\u8c03\u7528\u4e00\u6b21\uff0c\u6587\u4ef6\u6e38\u6807\u5c31\u52a01\uff0c\u5047\u5982\u8fde\u7eed\u8c03\u7528\u4e86N\u6b21\uff0c\u6e38\u6807pos\u90fd\u4f1a\u8054\u901a\u5230\u53f3\u56fe\u6240\u793a\u4f4d\u7f6e\uff1a<\/p>\n <\/p>\n \u4e4b\u524d\u4ecb\u7ecd\u7684\u200bgetChar()\u3001\u200bputChar()\uff0c\u5047\u5982\u8bfb\u5199\u6b63\u786e\u5c31\u4f1a\u4f7fpos\u624b\u52a8\u52a01\uff0cungetChar()\u51fd\u6570\u5047\u5982\u64cd\u4f5c\u6b63\u786e\uff0c\u8fd9\u4e48\u4f1a\u4f7fpos\u624b\u52a8\u51cf\u4e00\uff0c\u8fd9\u4e2a\u6e38\u6807\u90fd\u662fQFile\u624b\u52a8\u63a7\u5236\uff0c\u901a\u5e38\u4e0d\u987b\u8981\u81ea\u52a8\u8054\u901a\u6e38\u6807\u3002<\/p>\n \u3010\u9886\u66f4\u591aQT\u5b66\u4e60\u8d44\u6599\uff0c\u70b9\u51fb\u4e0b\u65b9\u94fe\u63a5\u514d\u8d39\u53d1\u653e\u2193\u2193\uff0c\u5148\u7801\u4f4f\u4e0d\u8d70\u5931~\u3011<\/p>\n \u70b9\u51fb\u2192\u9886\u53d6\u300c\u94fe\u63a5\u300d<\/p>\n \u6211\u4eec\u5bf9\u6587\u4ef6\u8bfb\u53d6\u5230\u4e00\u5b9a\u7a0b\u5ea6\uff0c\u90fd\u4f1a\u8bfb\u5230\u6587\u4ef6\u672b\u5c3e\u4f4d\u7f6e\uff0c\u62b5\u8fbe\u672b\u5c3e\u4ee5\u540e\u5c31\u96be\u4ee5\u518d\u8bfb\u6570\u636e\u4e86\uff0c\u7531\u4e8e\u6e38\u6807\u65e9\u5df2\u8d85\u51fa\u8303\u56f4\uff1a<\/p>\n <\/p>\n QFile\u5b50\u7c7b\u6709\u5feb\u6377\u51fd\u6570\u5224\u5b9a\u6587\u4ef6\u6e38\u6807\u662f\u5426\u5df2\u62b5\u8fbe\u6587\u4ef6\u672b\u5c3e\uff1a<\/p>\n \n \u5bf9\u4e8e\u5b57\u8282\u8bfb\u53d6\u51fd\u6570\uff0c\u6587\u4ef6\u6e38\u6807\u662f\u6309\u4e00\u5b57\u8282\u8054\u901a\u7684\uff0c\u5047\u5982\u8981\u8bfb\u53d6\u5927\u6bb5\u6570\u636e\u5757\uff0c\u8fd9\u4e48\u53ef\u4ee5\u4f7f\u7528\u4e0b\u8fb9\u7684\u51fd\u6570\uff1a<\/p>\n \n data\u4e00\u822c\u662f\u7a0b\u5e8f\u5458\u81ea\u52a8\u5206\u914d\u7684\u7f13\u51b2\u533alinux \u6587\u4ef6\u5207\u5272<\/strong>\uff0c\u4f8b\u5982char*buff=newchar[256];<\/p>\n maxSize\u5c31\u662f\u6700\u591a\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u91cf\uff0c\u901a\u5e38\u662f\u81ea\u52a8\u5206\u914d\u7684\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u4f8b\u5982256\u3002<\/p>\n \u8be5\u51fd\u6570\u8fd4\u56de\u503c\u901a\u5e38\u5c31\u662f\u6b63\u786e\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u91cf\uff0c\u7531\u4e8e\u5047\u5982\u6587\u4ef6\u524d\u9762\u82e5\u679c\u6ca1\u6709256\u5b57\u8282\uff0c\u8fd9\u4e48\u6709\u51e0\u4e2a\u5b57\u8282\u8bfb\u51e0\u4e2a\u5b57\u8282\u3002<\/p>\n \u5047\u5982read()\u51fd\u6570\u5728\u8bfb\u53d6\u4e4b\u524d\u5c31\u5230\u4e86\u6587\u4ef6\u672b\u5c3e\u6216\u5219\u8bfb\u53d6\u9519\u8bef\uff0c\u8fd9\u4e48\u8fd4\u56de\u503c\u662f-1\u3002\u5bf9\u4e8e\u4f7f\u7528QIODevice::WriteOnly\u53ea\u5199\u6a21\u5f0f\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u4e00\u822c\u6587\u4ef6\u6e38\u6807\u603b\u662f\u6307\u5411\u6587\u4ef6\u672b\u5c3e\uff0c\u8fd9\u65f6\u4faf\u8c03\u7528read()\u6ca1\u610f\u4e49\uff0c\u6240\u4ee5read()\u8fd4\u56de\u503c\u5c31\u662f-1\u3002<\/p>\n \u81ea\u52a8\u5206\u914d\u7f13\u51b2\u533a\u867d\u7136\u662f\u6bd4\u8f83\u9ebb\u70e6\u7684\u4e8b\u60c5\uff0c\u6211\u4eecQt\u539f\u751f\u6001\u7684\u8bfb\u53d6\u51fd\u6570\u5e94\u5f53\u7528\u4e0b\u8fb9\u8fd9\u4e2a\uff1a<\/p>\n \n \u8fd9\u513f\u7684read()\u51fd\u6570\u4f1a\u628a\u8bfb\u53d6\u7684\u5b57\u8282\u5b57\u6bb5\u5b58\u5230QByteArray\u5bf9\u8c61\u5e76\u8fd4\u56de\uff0c\u53c2\u6570\u91cc\u7684maxSize\u5c31\u662f\u6700\u591a\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u91cf\u3002\u8fd4\u56de\u7684QByteArray\u5bf9\u8c61\u4e0a\u9762\uff0c\u53ef\u4ee5\u7528QByteArray\u81ea\u5df1\u7684QByteArray::\u200bsize()\u51fd\u6570\u5224\u5b9a\u8bfb\u4e86\u591a\u5c11\u5b57\u8282\uff0c\u5047\u5982\u6587\u4ef6\u524d\u9762\u6ca1\u5b57\u8282\u53ef\u8bfb\u6216\u8bfb\u53d6\u9519\u8bef\uff0c\u8fd9\u4e48QByteArray\u89c4\u683c\u5c31\u662f0\u3002<\/p>\n \n readAll()\u51fd\u6570\u770b\u540d\u5b50\u5c31\u6653\u5f97\uff0c\u628a\u6587\u4ef6\u7684\u5168\u90e8\u5185\u5bb9\u76f4\u63a5\u8bfb\u53d6\u5230QByteArray\u5bf9\u8c61\u4e4b\u540e\u8fd4\u56de\u3002<\/p>\n \u53e6\u5916\u8fd8\u6709\u4e24\u4e2a\u66f4\u5b9e\u7528\u7684\u8bfb\u53d6\u884c\u7684\u51fd\u6570\uff1a<\/p>\n \n \u7b2c\u4e00\u4e2a\u200breadLine()\u662f\u7a0b\u5e8f\u5458\u81ea\u52a8\u5206\u914d\u7f13\u51b2\u533a\uff0c\u7b2c\u4e8c\u4e2a\u4e0d\u987b\u8981\u81ea\u52a8\u5206\u914d\u7f13\u51b2\u533a\u3002<\/p>\n readLine()\u51fd\u6570\u5de5\u4f5c\u7279\u70b9\u6bd4\u8f83\u7279\u6b8a\uff0c\u5b83\u662f\u4ece\u6587\u4ef6\u6216\u8bbe\u5907\u4e0a\u9762\u8bfb\u53d6\u4e00\u884cASCII\u5b57\u7b26\uff0c\u6700\u591a\u8bfb\u53d6maxSize-1\u5b57\u8282\uff0c\u7531\u4e8e\u6700\u540e\u4e00\u4e2a\u5b57\u8282\u9884\u7559\u7ed9\u5b57\u7b26\u4e32\u7ed3\u5c3eNULL\u5b57\u7b26\u3002<\/p>\n \u8be5\u51fd\u6570\u8fd4\u56de\u503c\u662f\u771f\u5b9e\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u91cf\uff0c\u5047\u5982\u8bfb\u53d6\u51fa\u9519\u6216\u65e0\u6570\u636e\u53ef\u8bfb\u5c31\u8fd4\u56de-1\u3002<\/p>\n \u200breadLine()\u603b\u4f1a\u5728\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u7b26\u4e32\u672b\u5c3e\u4f1a\u624b\u52a8\u6dfb\u52a0\u4e00\u4e2a\u5b57\u7b26\u4e32\u7ec8\u7ed3\u7b260\u3002<\/p>\n \u200breadLine()\u4f1a\u4ecd\u7136\u8bfb\u53d6\u6570\u636e\u76f4\u81f3\u5982\u4e0b\u4e09\u4e2a\u6761\u4ef6\u4e4b\u4e00\u6ee1\u8db3\uff1a<\/p>\n \u2460\u7b2c\u4e00\u4e2a'n'\u5b57\u7b26\u8bfb\u53d6\u5230\u7f13\u51b2\u533a\u3002<\/p>\n \u2461maxSize-1\u5b57\u8282\u6570\u5df2\u8bfb\u53d6\uff0c\u6700\u540e\u4e00\u4e2a\u5b57\u8282\u9884\u7559\u7ed90\u3002<\/p>\n \u2462\u6587\u4ef6\u6216\u8bbe\u5907\u8bfb\u53d6\u65e9\u5df2\u5230\u672b\u5c3e\u3002<\/p>\n \u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u4e2d\u6b62\u6761\u4ef6\uff0c\u771f\u5b9e\u8bfb\u53d6\u5230\u4e86'n'\u5b57\u7b26\uff0c\u8fd9\u4e48\u8fd9\u4e2a\u6362\u884c\u5b57\u7b26\u4f1a\u586b\u5145\u5230\u7f13\u51b2\u533a\u4e0a\u9762\uff1b<\/p>\n \u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u548c\u7b2c\u4e09\u4e2a\u4e2d\u6b62\u6761\u4ef6\uff0c\u662f\u6ca1\u6709\u8bfb\u5230'n'\u5b57\u7b26\uff0c\u8fd9\u4e48\u8be5\u51fd\u6570\u4e0d\u4f1a\u624b\u52a8\u6dfb\u52a0\u6362\u884c\u7b26\u5230\u672b\u5c3e\u3002<\/p>\n \u8fd8\u6709\u4e00\u4e2a\u7279\u6b8a\u60c5\u51b5\u8981\u6ce8\u610f\uff0creadLine()\u51fd\u6570\u4f1a\u628aWindows\u7684\u6587\u4ef6\u6362\u884c\u98ce\u683c\"rn\"\u624b\u52a8\u66ff\u6362\u6539\u4e3a'n'\u3002<\/p>\n \u200bread()\u548creadAll()\u3001\u200breadLine()\u51fd\u6570\u5c31\u4f1a\u8054\u901a\u6587\u4ef6\u6e38\u6807\uff0c\u5177\u4f53\u662f\u770b\u771f\u5b9e\u8bfb\u4e86\u591a\u5c11\u5b57\u8282\u3002<\/p>\n \u4ee5\u4e0a\u4e3b\u8981\u662f\u8bfb\u64cd\u4f5c\uff0c\u5199\u64cd\u4f5c\u4e0d\u4ec5putChar()\uff0c\u8fd8\u6709\u5982\u4e0b\u4e09\u4e2a\u5199\u51fd\u6570\uff1a<\/p>\n \n data\u5c31\u662f\u7f13\u51b2\u533a\u6570\u636e\u8868\u9488qq linux\uff0cmaxSize\u662f\u6700\u591a\u5199\u5165\u7684\u5b57\u8282\u6570\u3002\u8fd4\u56de\u503c\u662f\u771f\u5b9e\u5199\u5165\u7684\u5b57\u8282\u6570\uff0c\u7531\u4e8e\u53ef\u80fd\u51fa\u73b0c\u76d8\u4e0d\u591f\u7684\u60c5\u51b5\u3002\u5047\u5982\u8fd4\u56de\u503c\u662f-1\uff0c\u8fd9\u4e48\u53ef\u80fd\u662f\u5199\u5165\u51fa\u9519\u6216\u5219\u65e0\u5199\u5165\u6743\u9650\u3002\u8fd9\u4e2a\u5199\u51fd\u6570\u4e0d\u5206\u8fa8data\u7f13\u51b2\u533a\u4e0a\u9762\u7684''\u5b57\u7b26\u548c\u666e\u901a\u5b57\u7b26\u4e32\u5b57\u7b26\uff0c\u90fd\u4e00\u80a1\u8111\u5199\u8fdb\u53bb\u3002<\/p>\n \n \u8fd9\u7b2c\u4e8c\u4e2a\u51fd\u6570\u53c2\u6570\u6ca1\u6307\u5b9a\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u4f1a\u5c06\u53c2\u6570\u91cc\u7684data\u5f53\u6210''\u7ed3\u5c3e\u7684\u666e\u901a\u5b57\u7b26\u4e32\uff0c\u5199\u5165\u8be5\u5b57\u7b26\u4e32\u3002\u8fd9\u4e2a\u51fd\u6570\u7b49\u4ef7\u4e8e\u4e0b\u8fb9\u8fd9\u53e5\u4ee3\u7801\uff1a<\/p>\n \n \u7b2c\u4e09\u4e2a\u5199\u51fd\u6570\u867d\u7136\u66f4\u5e38\u7528\uff1a<\/p>\n \n byteArray\u4e0a\u9762\u6709\u591a\u5c11\u5b57\u8282\u5c31\u5199\u5165\u591a\u5c11\uff0c\u8fd9\u4e2a\u4e5f\u662f\u4e0d\u5206\u8fa8''\u5b57\u7b26\u548c\u666e\u901a\u5b57\u7b26\u4e32\u5b57\u7b26\uff0c\u90fd\u4e00\u80a1\u8111\u5199\u8fdb\u53bb\u3002<\/p>\n \u5199\u64cd\u4f5c\u51fd\u6570\u4e5f\u5c31\u4f1a\u8054\u901a\u6587\u4ef6\u6e38\u6807pos\uff0c\u5177\u4f53\u662f\u770b\u5b9e\u9645\u5199\u5165\u4e86\u591a\u5c11\u5b57\u8282\u3002<\/p>\n <\/p>\n \u901a\u5e38\u6211\u4eec\u90fd\u4e0d\u987b\u8981\u81ea\u52a8\u63a7\u5236\u6587\u4ef6\u6e38\u6807pos\uff0c\u800c\u4e14\u5047\u5982\u6709\u7279\u6b8a\u60c5\u51b5\uff0c\u987b\u8981\u81ea\u52a8\u79fb\u6e38\u6807\uff0c\u8fd9\u4e48\u901a\u8fc7\u4e0b\u8fb9\u51fd\u6570\uff1a<\/p>\n \n \u200bseek\u51fd\u6570\u82e5\u679c\u6210\u529f\u8054\u901a\u6e38\u6807\uff0c\u8fd9\u4e48\u4f1a\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\u3002\u6700\u597d\u4e0d\u8981\u7528seek\u51fd\u6570\u8054\u901a\u6e38\u6807\u5230\u8d85\u51fa\u6587\u4ef6\u89c4\u683c\u7684\u4f4d\u7f6e\uff0c\u8fd9\u6837\u4f1a\u9020\u6210\u96be\u4ee5\u610f\u6599\u7684\u7ed3\u679c\u3002<\/p>\n \u5047\u5982\u5e0c\u671b\u8bbe\u7f6e\u6587\u4ef6\u89c4\u683c\uff0c\u63d0\u65e9\u5728c\u76d8\u4e0a\u5206\u914d\u7a7a\u95f4\uff0c\u53ef\u4ee5\u7528\u5982\u4e0b\u51fd\u6570\uff1a<\/p>\n \n \u53c2\u6570sz\u5c31\u662f\u65b0\u7684\u6587\u4ef6\u5927\u5c0f\uff0c\u5047\u82e5\u65b0\u5927\u5c0f\u6bd4\u65e7\u7684\u5927\uff0c\u8fd9\u4e48\u65b0\u589e\u7a7a\u95f4\u5185\u5bb9\u662f\u968f\u673a\u7684\uff0c\u987b\u8981\u7a0b\u5e8f\u5458\u4e4b\u540e\u81ea\u52a8\u586b\u5145\u6570\u636e\u3002\u91cd\u7f6e\u5927\u5c0f\u6210\u529f\u5c31\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\u3002<\/p>\n \u6587\u4ef6\u6253\u5f00\u548c\u8bfb\u5199\u64cd\u4f5c\u7ed3\u675f\u4ee5\u540e\uff0c\u5c31\u53ef\u4ee5\u5173\u6389\u6587\u4ef6\uff1a<\/p>\n \n \u5728\u5199\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u5047\u5982\u987b\u8981\u7acb\u523b\u628aQt\u5185\u90e8\u5199\u7f13\u51b2\u533a\u7684\u6570\u636e\u5199\u5165c\u76d8\uff0c\u53ef\u4ee5\u8c03\u7528\uff1a<\/p>\n \n \uff083\uff09\u6587\u4ef6\u5c5e\u6027\u548c\u6743\u9650\u7b49\u51fd\u6570<\/p>\n QFile\u6709\u90e8\u4efd\u51fd\u6570\u663e\u7136\u4e0eQFileInfo\u7c7b\u529f\u80fd\u5dee\u4e0d\u591a\uff0c\u8fd9\u513f\u5927\u81f4\u8bb2\u89e3\u4e00\u4e0b\uff0c\u5bf9\u4e8e\u8fd9\u90e8\u4efd\u64cd\u4f5c\uff0c\u867d\u7136\u66f4\u5efa\u8bae\u7528QFileInfo\u6216QDir\u7c7b\u6765\u5b9e\u73b0\u3002<\/p>\n \n \u628a\u5f53\u524d\u6587\u4ef6\u590d\u5236\u5230\u65b0\u6587\u4ef6newName\uff0c\u590d\u5236\u6210\u529f\u5c31\u8fd4\u56detrue\uff0c\u5426\u548b\u8fd4\u56defalse\u3002<\/p>\n \u6ce8\u610f\u5047\u5982newName\u65b0\u6587\u4ef6\u4e4b\u524d\u65e9\u5df2\u5b58\u5728\uff0c\u8fd9\u4e48copy()\u51fd\u6570\u8fd4\u56defalse\uff0c\u5b83\u4e0d\u4f1a\u8986\u76d6\u65e7\u6587\u4ef6\u3002<\/p>\n \u5f53\u590d\u5236\u6587\u4ef6\u65f6\uff0c\u6e90\u6587\u4ef6\u624b\u52a8\u4f1a\u88ab\u5173\u6389\uff0c\u4e4b\u540e\u4f7f\u7528\u6e90\u6587\u4ef6\u6700\u597d\u518d\u91cd\u65b0\u6253\u5f00\u3002<\/p>\n \n \u5224\u5b9a\u5f53\u524d\u6587\u4ef6\u662f\u5426\u5b58\u5728\u3002<\/p>\n \n \u4e3a\u5f53\u524d\u6587\u4ef6\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5feb\u6377\u65b9\u6cd5linkName\uff0c\u521b\u5efa\u6210\u529f\u8fd4\u56detrue\uff0c\u521b\u5efa\u5931\u8d25\u8fd4\u56defalse\u3002\u200blink()\u51fd\u6570\u4e5f\u4e0d\u4f1a\u8986\u76d6\u4e4b\u524d\u5df2\u5b58\u5728\u7684\u5feb\u6377\u65b9\u6cd5\u3002\u5bf9\u4e8eWindows\u7cfb\u7edf\uff0c\u5feb\u6377\u65b9\u6cd5\u540d\u5fc5\u987b\u4ee5.lnk\u7ed3\u5c3e\uff0c\u5426\u5219\u4f1a\u51fa\u9519\u3002<\/p>\n \n \u5220\u6389\u5f53\u524d\u6587\u4ef6\uff0c\u5220\u6389\u4e4b\u524d\u6587\u4ef6\u4f1a\u624b\u52a8\u88ab\u5173\u6389\uff0c\u4e4b\u540e\u5220\u6389\u3002<\/p>\n \n \u628a\u5f53\u524d\u6587\u4ef6\u91cd\u547d\u540d\u4e3a\u65b0\u540d\u5b50newName\uff0c\u82e5\u679c\u6210\u529f\u8fd4\u56detrue\uff0c\u5931\u8d25\u8fd4\u56defalse\u3002\u5047\u5982newName\u6587\u4ef6\u4e4b\u524d\u5df2\u5b58\u5728\uff0c\u8fd9\u4e48\u91cd\u547d\u540d\u4f1a\u5931\u8d25\uff0c\u65e7\u6587\u4ef6\u4e0d\u4f1a\u88ab\u8986\u76d6\u3002\u6587\u4ef6\u91cd\u547d\u540d\u4e4b\u524d\uff0c\u8be5\u6587\u4ef6\u4e5f\u4f1a\u624b\u52a8\u5173\u6389\u3002<\/p>\n \nQFile(const QString & name)\nQFile(QObject * parent)\nQFile(const QString & name, QObject * parent)<\/code><\/pre>\n<\/p>\n
void QFile::setFileName(const QString & name)<\/code><\/pre>\n<\/p>\n
bool QFile::\u200bopen(OpenMode mode)<\/code><\/pre>\n<\/p>\n
file.open(QIODevice::ReadOnly); \/\/\u4ee5\u53ea\u8bfb\u65b9\u5f0f\u6253\u5f00\u6587\u4ef6\nfile.open(QIODevice::ReadOnly | QIODevice::Text); \/\/\u786e\u5b9a\u662f\u8bfb\u53d6\u6587\u672c\u6587\u4ef6\uff0c\u5e76\u4e14\u81ea\u52a8\u628a\u6362\u884c\u7b26\u4fee\u6539\u4e3a 'n'<\/code><\/pre>\n<\/p>\n
file.open(QIODevice::WriteOnly); \/\/\u4ee5\u53ea\u5199\u6a21\u5f0f\u6253\u5f00\uff0c\u8fd9\u4e2a\u6a21\u5f0f\u6697\u542b Truncate\uff0c\u4f1a\u6e05\u7a7a\u65e7\u6570\u636e\nfile.open(QIODevice::WriteOnly | QIODevice::Truncate); \/\/\u53ea\u5199\u6a21\u5f0f\uff0c\u6e05\u7a7a\u65e7\u6570\u636e\nfile.open(QIODevice::WriteOnly | QIODevice::Append); \/\/\u53ea\u5199\u548c\u8ffd\u52a0\u6a21\u5f0f\uff0c\u4e0d\u4f1a\u6e05\u7a7a\u65e7\u6570\u636e<\/code><\/pre>\n<\/p>\n
file.open(QIODevice::ReadWrite); \/\/\u8bfb\u5199\u6a21\u5f0f\uff0c\u65e7\u6570\u636e\u4e0d\u4f1a\u6e05\u7a7a\uff0c\u53ef\u4ee5\u8bfb\u51fa\u6765<\/code><\/pre>\n<\/p>\n
bool QFile::\u200bopen(FILE * fh, OpenMode mode, FileHandleFlags handleFlags = DontCloseHandle)\nbool QFile::\u200bopen(int fd, OpenMode mode, FileHandleFlags handleFlags = DontCloseHandle)<\/code><\/pre>\n<\/p>\n
bool QIODevice::\u200bgetChar(char * c)<\/code><\/pre>\n<\/p>\n
void QIODevice::\u200bungetChar(char c)<\/code><\/pre>\n<\/p>\n
bool QIODevice::\u200bputChar(char c)<\/code><\/pre>\n<\/p>\n
qint64 QFile::\u200bsize() const<\/code><\/pre>\n<\/p>\n
qint64 QFileDevice::\u200bpos() const<\/code><\/pre>\n<\/p>\n
bool QFileDevice::\u200batEnd() const<\/code><\/pre>\n<\/p>\n
qint64 QIODevice::\u200bread(char * data, qint64 maxSize)<\/code><\/pre>\n<\/p>\n
QByteArray QIODevice::\u200bread(qint64 maxSize)<\/code><\/pre>\n<\/p>\n
QByteArray QIODevice::\u200breadAll()<\/code><\/pre>\n<\/p>\n
qint64 QIODevice::\u200breadLine(char * data, qint64 maxSize)\nQByteArray QIODevice::\u200breadLine(qint64 maxSize = 0)<\/code><\/pre>\n<\/p>\n
qint64 QIODevice::\u200bwrite(const char * data, qint64 maxSize)<\/code><\/pre>\n<\/p>\n
qint64 QIODevice::\u200bwrite(const char * data)<\/code><\/pre>\n<\/p>\n
QIODevice::write(data, qstrlen(data));<\/code><\/pre>\n<\/p>\n
qint64 QIODevice::\u200bwrite(const QByteArray & byteArray)<\/code><\/pre>\n<\/p>\n
bool QFileDevice::\u200bseek(qint64 pos)<\/code><\/pre>\n<\/p>\n
bool QFile::\u200bresize(qint64 sz)<\/code><\/pre>\n<\/p>\n
void QFileDevice::\u200bclose()<\/code><\/pre>\n<\/p>\n
bool QFileDevice::\u200bflush() \/\/\u8fd9\u4e2a\u51fd\u6570\u5f88\u5c11\u7528\u5230\uff0c\u6587\u4ef6\u5173\u95ed\u65f6\u81ea\u52a8\u4f1a\u6267\u884c flush<\/code><\/pre>\n<\/p>\n
bool QFile::\u200bcopy(const QString & newName)<\/code><\/pre>\n<\/p>\n
bool QFile::\u200bexists() const<\/code><\/pre>\n<\/p>\n
bool QFile::\u200blink(const QString & linkName)<\/code><\/pre>\n<\/p>\n
bool QFile::\u200bremove()<\/code><\/pre>\n<\/p>\n
bool QFile::\u200brename(const QString & newName)<\/code><\/pre>\n<\/p>\n
QString QFile::\u200bsymLinkTarget() const<\/code><\/pre>\n<\/p>\n