本文整理汇总了C++中FileHandle::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ FileHandle::toString方法的具体用法?C++ FileHandle::toString怎么用?C++ FileHandle::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHandle
的用法示例。
在下文中一共展示了FileHandle::toString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copyTo
/** Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a
* file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination
* doesn't exist, {@link #mkdirs()} is called on the destination's parent and this file is copied into it with a new name. If
* this handle is a directory, then 1) if the destination is a file, GdxRuntimeException is thrown, or 2) if the destination is
* a directory, this directory is copied recursively into it as a subdirectory, overwriting existing files, or 3) if the
* destination doesn't exist, {@link #mkdirs()} is called on the destination and this directory is copied recursively into it
* as a subdirectory.
* @throw GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file,
* or copying failed. */
void FileHandle::copyTo(const FileHandle& destination) const
{
/*
boolean sourceDir = isDirectory();
if (!sourceDir) {
if (dest.isDirectory()) dest = dest.child(name());
copyFile(this, dest);
return;
}
if (dest.exists()) {
if (!dest.isDirectory()) throw GdxRuntimeException("Destination exists but is not a directory: " + dest);
} else {
dest.mkdirs();
if (!dest.isDirectory()) throw GdxRuntimeException("Destination directory cannot be created: " + dest);
}
if (!sourceDir) dest = dest.child(name());
copyDirectory(this, dest);
*/
FileHandle dest = destination;
bool sourceIsDir = isDirectory();
if (!sourceIsDir)
{
if (dest.isDirectory())
{
dest = dest.child(name());
}
copyFile(*this, dest);
return;
}
if (dest.exists())
{
if (!dest.isDirectory())
throw GdxRuntimeException("Destination exists but is not a directory: " + dest.toString());
}
else
{
dest.mkdirs();
if (!dest.isDirectory())
throw GdxRuntimeException("Destination directory cannot be created: " + dest.toString());
}
if (!sourceIsDir)
{
dest = dest.child(name());
}
copyDirectory(*this, dest);
}
示例2: create
void FilesTest::create()
{
font = new BitmapFont();
batch = new SpriteBatch();
if(Gdx.files->isExternalStorageAvailable())
{
message += "External storage available\n";
std::string externalStoragePath;
Gdx.files->getExternalStoragePath(externalStoragePath);
message += "External storage path: " + externalStoragePath + "\n";
try
{
FileHandle cube = Gdx.files->internalHandle("data/cube.obj");
std::ifstream in;
cube.read(in);
try
{
in.close();
}
catch(std::exception e)
{
}
message += "Open internal success\n";
}
catch(std::exception e)
{
message += "Couldn't open internal data/cube.obj\n";
message += e.what();
message += "\n";
}
try
{
FileHandle testFile = Gdx.files->externalHandle("test.txt");
std::ofstream testStream;
testFile.write(false, testStream);
testStream << "test";
testStream.close();
message += "Write external success\n";
}
catch(GdxRuntimeException ex)
{
message += "Couldn't open externalstorage/test.txt\n";
}
catch(std::exception e)
{
message += "Couldn't write externalstorage/test.txt\n";
}
try
{
FileHandle testFile = Gdx.files->externalHandle("test.txt");
std::ifstream in;
testFile.read(in);
in.close();
message += "Open external success\n";
}
catch(GdxRuntimeException e)
{
message += "Couldn't open internal externalstorage/test.txt\n";
}
FileHandle file = Gdx.files->externalHandle("test.txt");
if(!file.remove())
{
message += "Couldn't delete externalstorage/test.txt";
}
file = Gdx.files->externalHandle("this/is/a/test");
file.mkdirs();
file.remove();
if(!file.parent().remove())
message += "failed to remove this/is/a/ directory";
if(!file.parent().parent().parent().removeRecursive())
message += "failed to remove this directory";
}
else
{
message += "External storage not available";
}
FileHandle tmp = FileHandle::tempFile();
tmp.length();
message += "Temp file created: " + tmp.toString() + "\n";
tmp.remove();
tmp = FileHandle::tempDirectory();
if(!tmp.isDirectory())
fail();
message += "Temp directory created: " + tmp.toString() + "\n";
tmp.remove();
try
{
testInternal();
testExternal();
//.........这里部分代码省略.........