程序运行目录:分为E盘bin目录和build-debug目录,测试文件名称为:pathFile.txt
代码如下:
QFile *file = new QFile;
file->setFileName(ui->lineEdit->text());
ui->label->setText(file->exists()?"文件存在":"文件不存在");
if(file->exists())
{
file->open(QIODevice::ReadWrite);
ui->textEdit->append(file->readAll());
}
if(file->isOpen())
{
file->close();
}
PathName结论
./PathFile.txt .//PathFile.txt .///PathFile.txt 或PathFile.txttrue
.\PathFile.txt .双\PathFile.txt .三\PathFile.txttrue
所有不带.的单双多/及\false
文件放在build-debug目录的上级目录
PathName结论
./../PathFile.txttrue
./..\PathFile.txttrue
.双/..\PathFile.txt ./..双\PathFile.txt 等true
类似/../PathFile.txt 统统不可false
文件放在E盘bin目录下
PathName结论
E:\bin\PathFile.txt E:双\bin\PathFile.txt E:\bin双\PathFile.txttrue
E:/bin/PathFile.txt E:双/bin/PathFile.txt E:/bin双/PathFile.txttrue
E:/bin\PathFile.txt E:双/bin\PathFile.txttrue
文件放在E盘bin目录的上级目录,即:E盘符下
PathName结论
E:/bin/../PathFile.txttrue
E:双/bin/..双\PathFile.txt 等true
现对自己模糊知识点做一个总结,如有错误,恳请批评指正
网友评论