use of java.io.FileOutputStream in project KJFrameForAndroid by kymjs.
the class ImageUtils method getSmallImageFile.
/**
* 压缩图片
*
* @param filePath 源图片地址
* @param width 想要的宽度
* @param height 想要的高度
* @param isAdjust 是否自动调整尺寸, true图片就不会拉伸,false严格按照你的尺寸压缩
* @return Bitmap
*/
public static File getSmallImageFile(Context cxt, String filePath, int width, int height, boolean isAdjust) {
Bitmap bitmap = reduce(BitmapFactory.decodeFile(filePath), width, height, isAdjust);
File file = new File(getRandomFileName(cxt.getCacheDir().getPath()));
BufferedOutputStream outputStream = null;
try {
outputStream = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 60, outputStream);
outputStream.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}
use of java.io.FileOutputStream in project eweb4j-framework by laiweiwei.
the class BeanXMLWriter method write.
public File write() throws Exception {
Document doc = createDoc();
// 读取文件
FileOutputStream fos = new FileOutputStream(this.file);
// 设置文件编码
OutputFormat format = OutputFormat.createPrettyPrint();
// 创建写文件方法
org.dom4j.io.XMLWriter xmlWriter = new org.dom4j.io.XMLWriter(fos, format);
// 写入文件
xmlWriter.write(doc);
// 关闭
fos.close();
xmlWriter.close();
return this.file;
}
use of java.io.FileOutputStream in project eweb4j-framework by laiweiwei.
the class FileUtil method writeFile.
public static void writeFile(File f, String content) throws Exception {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "utf-8"));
writer.write(content);
} catch (Exception e) {
throw e;
} finally {
if (writer != null) {
try {
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of java.io.FileOutputStream in project libgdx by libgdx.
the class SharedLibraryLoader method extractFile.
private File extractFile(String sourcePath, String sourceCrc, File extractedFile) throws IOException {
String extractedCrc = null;
if (extractedFile.exists()) {
try {
extractedCrc = crc(new FileInputStream(extractedFile));
} catch (FileNotFoundException ignored) {
}
}
// If file doesn't exist or the CRC doesn't match, extract it to the temp dir.
if (extractedCrc == null || !extractedCrc.equals(sourceCrc)) {
try {
InputStream input = readFile(sourcePath);
extractedFile.getParentFile().mkdirs();
FileOutputStream output = new FileOutputStream(extractedFile);
byte[] buffer = new byte[4096];
while (true) {
int length = input.read(buffer);
if (length == -1)
break;
output.write(buffer, 0, length);
}
input.close();
output.close();
} catch (IOException ex) {
throw new GdxRuntimeException("Error extracting file: " + sourcePath + "\nTo: " + extractedFile.getAbsolutePath(), ex);
}
}
return extractedFile;
}
use of java.io.FileOutputStream in project libgdx by libgdx.
the class SharedLibraryLoader method canWrite.
/** Returns true if the parent directories of the file can be created and the file can be written. */
private boolean canWrite(File file) {
File parent = file.getParentFile();
File testFile;
if (file.exists()) {
if (!file.canWrite() || !canExecute(file))
return false;
// Don't overwrite existing file just to check if we can write to directory.
testFile = new File(parent, UUID.randomUUID().toString());
} else {
parent.mkdirs();
if (!parent.isDirectory())
return false;
testFile = file;
}
try {
new FileOutputStream(testFile).close();
if (!canExecute(testFile))
return false;
return true;
} catch (Throwable ex) {
return false;
} finally {
testFile.delete();
}
}
Aggregations