Created
July 28, 2017 12:18
-
-
Save oianmol/adc66f361e6dafdf9ccf3a8f40d636e9 to your computer and use it in GitHub Desktop.
File Utils For Gboard edittext extension keyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileUtils{ | |
@NotNull | |
public static File buildImageKeyboardSupportUri(@Nullable String extension) { | |
final long fileId = System.currentTimeMillis(); | |
String filePath = Environment.getExternalStorageDirectory().toString() + | |
"/keyboardImage/.shared/iks" + String.valueOf(fileId) + | |
(android.text.TextUtils.isEmpty(extension) ? "" : ("." + extension)); | |
checkAndCreateDir(filePath); | |
return new File(filePath); | |
} | |
public static boolean checkAndCreateDir(String filePath) { | |
File tmp = new File(filePath); | |
File parentFile = tmp.getParentFile(); | |
if (!parentFile.exists() && !parentFile.mkdirs()) { | |
return false; | |
} | |
return true; | |
} | |
public static void copyFile(String fileFromPath, String fileToPath) | |
throws Exception { | |
InputStream in = null; | |
OutputStream out = null; | |
File f = new File(fileToPath); | |
if (!f.getParentFile().exists()) { | |
f.getParentFile().mkdirs(); | |
} | |
int bufferSize = 8196; | |
try { | |
in = new FileInputStream(fileFromPath); | |
out = new FileOutputStream(fileToPath); | |
int bytesRead = 0; | |
byte[] buffer = new byte[bufferSize]; | |
while ((bytesRead = in.read(buffer, 0, bufferSize)) != -1) { | |
out.write(buffer, 0, bytesRead); | |
} | |
} finally { | |
if (in != null) | |
in.close(); | |
if (out != null) | |
out.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment