FileUtils

public class FileUtils

Properties

Link copied to clipboard
public final static int FILE_SCHEME_LENGTH

Functions

Link copied to clipboard
public static File byte2File(Array<byte> buf, String filePath, String fileName)
Creates a file from a byte array.
Link copied to clipboard
public static Array<byte> contentFile2byte(Context context, Uri uri)
Gets the byte array of the specified file.
Link copied to clipboard
public static File convertBitmap2File(Bitmap bm, String dir, String name)
Converts a bitmap to a file.
Link copied to clipboard
public static boolean copyFile(Context context, Uri srcUri, String desPath)

public static File copyFile(File src, String path, String name)
public static boolean copyFile(String srcPath, String path, String name)
Copies a file.
Link copied to clipboard
public static boolean copyFileToInternal(Context context, Uri srcUri, String desPath, String name)
Link copied to clipboard
public static Array<byte> file2byte(File file)
Gets the byte array of the specified file.
public static Array<byte> file2byte(Context context, Uri uri)
Link copied to clipboard
public static String generateKey()
Link copied to clipboard
public static Array<byte> getByteFromUri(Uri uri)
Reads a file as bytes, commonly used for binary files such as images, audio, and video.
Link copied to clipboard
public static String getCacheDirsPath(Context context, String dir)
Gets the cache storage path, e.g.
Link copied to clipboard
public static String getCachePath(Context context)
public static String getCachePath(Context context, String dir)
Gets the cache storage path, e.g.
Link copied to clipboard
public static File getExternalCacheDir(Context context)
On versions below 9.
Link copied to clipboard
public static FileInfo getFileInfoByFile(File file)
Gets file name, size, and type from a File object.
Link copied to clipboard
public static FileInfo getFileInfoByUri(Context context, Uri uri)
Gets file name, size, and type from a URI.
Link copied to clipboard
public static InputStream getFileInputStream(String path)
Creates an input stream for reading the specified file into memory.
public static InputStream getFileInputStream(Context context, Uri uri)
Link copied to clipboard
public static String getFileKey(Object message)
Gets the key for a media message, used for image, video, GIF message handlers.
Link copied to clipboard
public static long getFileLengthWithUri(Context pContext, Uri pUri)
Gets the file length.
Link copied to clipboard
public static String getFileNameWithPath(String path)
Gets the file name from a file path.
Link copied to clipboard
public static long getFileSize(File file)
Gets the size of the specified file.
Link copied to clipboard
public static String getFileTypeFromByteData(Array<byte> data)
Link copied to clipboard
public static String getFileTypeFromInputStream(InputStream inputStream)
Detects the file type from an input stream.
Link copied to clipboard
public static String getInternalCachePath(Context context, String dir)
Gets the app internal cache path data/data/<package name>/cache/<dir>
Link copied to clipboard
public static String getJsonOutPath(Context context)
Link copied to clipboard
@Deprecated()
public static String getMediaDownloadDir(Context context)
public static String getMediaDownloadDir(Context context, String dir)
Gets the media file storage directory.
Link copied to clipboard
public static String getStringFromFile(String path)
Reads file content as a string.
Link copied to clipboard
public static String getSuffix(Uri srcUri)
Gets the file extension from a Uri.
public static String getSuffix(String path)
Gets the file extension from a path.
Link copied to clipboard
public static String getTempFileMD5(Context context, int messageId)
Gets the MD5 key for resumable file download, used to identify the file being downloaded.
public static String getTempFileMD5(Context context, String tag)
Gets the temporary file name for resumable download, used to identify the file being downloaded.
Link copied to clipboard
public static String getTempFilePath(Context context, int messageId)
public static String getTempFilePath(Context context, String id)
Gets the temporary file storage path for resumable downloads.
Link copied to clipboard
public static String getUrlFileName(String url, String fileName)
Link copied to clipboard
public static boolean isFileExistsWithUri(Context pContext, Uri pUri)
Checks whether a file exists.
Link copied to clipboard
public static boolean isValidateLocalUri(Uri pUri)
Checks whether the file Uri scheme starts with "file" or "content".
Link copied to clipboard
public static int readPictureDegree(Context context, String path)
Reads the rotation degree of an image.
Link copied to clipboard
public static void removeFile(String path)
Deletes a file.
Link copied to clipboard
public static String sanitizeFilename(String displayName)
Sanitizes the file name to prevent path traversal attacks.
Link copied to clipboard
public static void saveFile(String str, String filePath)
Saves a string to the specified file path.
Link copied to clipboard
public static boolean uriStartWithContent(Uri srcUri)
Checks whether the file Uri scheme starts with "content".
Link copied to clipboard
public static boolean uriStartWithFile(Uri pUri)
Checks whether the file Uri scheme starts with "file" and its length exceeds 7.
Link copied to clipboard
public static void writeByte(Uri uri, Array<byte> data)
Writes byte array sequentially to a file output stream.