public class GGPath
extends java.lang.Object
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
File f = new File("/mnt/sdcard/foo")
or File
f = new File("/mnt/sdcard/foo/")
is an abstraction for the subfolder
foo in the root of the sdcard. This is equivalent to
File f = new File("foo")
or File f = new ("foo/")
Modifier and Type | Method and Description |
---|---|
static void |
closeInputStream(java.io.InputStream is)
Closes the given input stream.
|
static void |
closeOutputStream(java.io.OutputStream os)
Closes the given output stream.
|
static boolean |
copyDirectory(java.io.File srcDir,
java.io.File destDir,
boolean collect)
Copies all files from the source directory into the destination directory.
|
static boolean |
copyFile(java.io.File src,
java.io.File dest)
Copies binary data from the source file to the destination file.
|
static boolean |
copyFile(java.net.URL url,
java.io.File dest)
Copies binary data from the source URL to the destination file.
|
static boolean |
copyTree(java.io.File srcDir,
java.io.File destDir)
Copies all files with subdirectory structure from the source directory to
the destination directory.
|
static boolean |
createDirectoryTree(java.io.File dirPath)
Creates a directory structure.
|
static int |
getNbFiles(java.io.File dirPath)
Returns number of files (subdirectories are not counted) in given directory.
|
static boolean |
isDirectoryEmpty(java.io.File dirPath)
Returns true, if the directory is empty (no files and no subdirectories).
|
static java.io.InputStream |
openRawResource(android.app.Activity activity,
java.lang.String filename)
Loads a binary file from the raw resource folder,
e.g. get a Bitmap reference from a image resource with bi = BitmapFactory.decodeStream(openRawResource(activity, filename). |
static boolean |
pack(java.io.File jarFile,
java.io.File dirPath)
Creates a compressed JAR archive from a all files and subdirectories
in directory with given dirPath.
|
static java.lang.String |
readTextFile(java.io.File filePath)
Reads a text file into a string.
|
static java.lang.String |
readTextResource(android.app.Activity activity,
java.lang.String filename)
Reads a text file from the raw resouce folder.
|
static boolean |
removeDir(java.io.File dirPath)
(Be very careful) Deletes all files and subdirectories and
the directory itself.
|
static boolean |
removeFiles(java.io.File dirPath,
boolean clean)
(Be very careful) Deletes all files in directory
(but not the directory itself).
|
static boolean |
unpack(java.io.File jarFile,
java.io.File dirPath)
Unpacks the given JAR archive in the given directory.
|
static boolean |
unzip(java.io.File zipFile,
java.io.File dirPath)
Unpacks the given ZIP archive in the given directory.
|
static boolean |
writeImageFile(android.graphics.Bitmap bm,
java.io.File filePath,
java.lang.String type,
boolean createTree)
Writes an image file in PNG (lossless), JPG (max quality) or
WEBP (max quality) of the given Bitmap.
|
static boolean |
writeTextFile(java.io.File filePath,
java.lang.String text,
boolean createTree)
Writes the given string to the given destination file.
|
static boolean |
zip(java.io.File zipFile,
java.io.File dirPath)
Creates a ZIP archive from a all files and subdirectories
in directory with given dirPath.
|
public static boolean writeImageFile(android.graphics.Bitmap bm, java.io.File filePath, java.lang.String type, boolean createTree)
bm
- the Bitmap to copyfilePath
- a relative or absolute path to the filetype
- the image file format. Only "jpg" and "png" are supportedcreateTree
- if true, a nonexistent subdirectory structure is createdpublic static boolean writeTextFile(java.io.File filePath, java.lang.String text, boolean createTree)
filePath
- a relative or absolute path to the filetext
- the text to writecreateTree
- if true, a nonexistent subdirectory structure is createdpublic static java.lang.String readTextFile(java.io.File filePath)
filePath
- a relative or absolute path to the filepublic static java.lang.String readTextResource(android.app.Activity activity, java.lang.String filename)
activity
- the current activityfilename
- the name of the file (without extension)public static java.io.InputStream openRawResource(android.app.Activity activity, java.lang.String filename)
activity
- the current activityfilename
- the name of the resource (without extension)public static void closeInputStream(java.io.InputStream is)
is
- the stream to closepublic static void closeOutputStream(java.io.OutputStream os)
os
- the stream to closepublic static boolean removeFiles(java.io.File dirPath, boolean clean)
dirPath
- path to a directory. A trailing file separator is ignoredclean
- if true, all subdirectories are removed also; otherwise only
files in dirPath are deleted and the subdirectories with their files are
maintainedpublic static boolean removeDir(java.io.File dirPath)
dirPath
- path to a directory. A trailing file separator is ignoredpublic static boolean createDirectoryTree(java.io.File dirPath)
dirPath
- a relative or absolute directory path that may contain
subdirectories, e.g. /dir/subdir1/subdir2. A trailing file separator is ignoredpublic static boolean copyFile(java.net.URL url, java.io.File dest)
<uses-permission android:name="android.permission.INTERNET" />
url
- the source URL, e.g. "http://myserver.com/image.gif"dest
- a relative or absolute file path of the destination filepublic static boolean copyFile(java.io.File src, java.io.File dest)
src
- a relative or absolute file path of the source filedest
- a relative or absolute file path of the destination filepublic static boolean copyDirectory(java.io.File srcDir, java.io.File destDir, boolean collect)
srcDir
- the source directory (absolute or relative)destDir
- the destination directory (absolute or relative)collect
- if true, all files in subdirectories of the source
directory are copied to the root of the destination directory
(use copyTree() to maintain the subdirectory structure under the destination
directory)public static boolean copyTree(java.io.File srcDir, java.io.File destDir)
srcDir
- the source directory (absolute or relative)destDir
- the destination directory (absolute or relative)public static int getNbFiles(java.io.File dirPath)
dirPath
- path to a directory. A trailing file separator is ignoredpublic static boolean isDirectoryEmpty(java.io.File dirPath)
dirPath
- path to a directory. A trailing file separator is ignoredpublic static boolean unpack(java.io.File jarFile, java.io.File dirPath)
jarFile
- the JAR to unpackdirPath
- path to a directory. A trailing file separator is ignoredpublic static boolean pack(java.io.File jarFile, java.io.File dirPath)
jarFile
- the JAR archive to createdirPath
- path to the directory that holds the
files/subdirectories to add to the archive. An emtpy directory is illegal.
A trailing file separator is ignoredpublic static boolean unzip(java.io.File zipFile, java.io.File dirPath)
zipFile
- the ZIP to unpackdirPath
- path to a directory. A trailing file separator is ignoredpublic static boolean zip(java.io.File zipFile, java.io.File dirPath)
zipFile
- the ZIP archive to createdirPath
- path to the directory that holds the
files/subdirectories to add to the archive. An empty directory is illegal.
A trailing file separator is ignored