本文整理汇总了Java中java.io.FileInputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java FileInputStream.close方法的具体用法?Java FileInputStream.close怎么用?Java FileInputStream.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.FileInputStream
的用法示例。
在下文中一共展示了FileInputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fileCombination
import java.io.FileInputStream; //导入方法依赖的package包/类
public static void fileCombination(File file, String targetFile) throws Exception {
outFile = new File(targetFile);
outDest = new RandomAccessFile(outFile,"rw");
childReader = new BufferedReader(new FileReader(file));
long temp = 0;
while ((name = childReader.readLine()) != null) {
cFile = new File(name);
long size = cFile.length();
fileReader = new FileInputStream(cFile);
read = fileReader.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, size);
out = outDest.getChannel().map(FileChannel.MapMode.READ_WRITE, temp, size);
temp += size;
for (long j = 0; j < size; j++) {
byte b = read.get();
out.put(b);
}
fileReader.close();
UnMap.unmap(read);
UnMap.unmap(out);
}
outDest.close();
childReader.close();
}
示例2: ReadDIASettingSerialization
import java.io.FileInputStream; //导入方法依赖的package包/类
public static DIA_Setting ReadDIASettingSerialization(String filepath) {
if (!new File(FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_diasetting.ser").exists()) {
return null;
}
try {
Logger.getRootLogger().debug("Reading DIA setting from file:" + FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_diasetting.ser...");
FileInputStream fileIn = new FileInputStream(FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_diasetting.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
DIA_Setting setting = (DIA_Setting) in.readObject();
in.close();
fileIn.close();
return setting;
} catch (Exception ex) {
Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
return null;
}
}
示例3: copyToAndroidData
import java.io.FileInputStream; //导入方法依赖的package包/类
private void copyToAndroidData(String sourcePath, String destPath) {
Log.i("nib", "dest: " + destPath + "\n" + "source:" + sourcePath);
try {
FileInputStream inputStream = new FileInputStream(new File(sourcePath));
FileOutputStream outputStream = new FileOutputStream(new File(destPath));
byte bt[] = new byte[1024];
int c;
while ((c = inputStream.read(bt)) > 0) {
outputStream.write(bt, 0, c);
}
inputStream.close();
outputStream.close();
ToastUtil.showShort(R.string.save_success);
btnSaveToLocal.setClickable(false);
Log.i("nib", "复制完成");
} catch (Exception e) {
Log.i("nib", e.toString());
}
}
示例4: zipIt
import java.io.FileInputStream; //导入方法依赖的package包/类
/**
* Zip it
*/
public void zipIt(){
byte[] buffer = new byte[1024];
try{
FileOutputStream fos = new FileOutputStream(OUTPUT_ZIP_FILE);
ZipOutputStream zos = new ZipOutputStream(fos);
//System.out.println("Output to Zip : " + zipFile);
for(String file : this.fileList){
//System.out.println("File Added : " + file);
ZipEntry ze= new ZipEntry(file);
zos.putNextEntry(ze);
FileInputStream in = new FileInputStream(SOURCE_FOLDER.getAbsolutePath() + File.separator + file);
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
in.close();
}
zos.closeEntry();
zos.close();
//System.out.println("Done");
} catch (IOException ex) {
ex.printStackTrace();
}
}
示例5: fileTxtRead
import java.io.FileInputStream; //导入方法依赖的package包/类
String fileTxtRead(String fileName)
{
String res="";
try
{
File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
int length = fis.available();
byte [] buffer = new byte[length];
fis.read(buffer);
res = EncodingUtils.getString(buffer, "UTF-8");
fis.close();
}
catch (IOException e)
{
e.printStackTrace();
}
return res;
}
示例6: loadBinary
import java.io.FileInputStream; //导入方法依赖的package包/类
/**
* Binary file load
*/
static public byte[] loadBinary(File binFile) throws IOException {
byte[] xferBuffer = new byte[10240];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i;
FileInputStream fis = new FileInputStream(binFile);
try {
while ((i = fis.read(xferBuffer)) > 0) {
baos.write(xferBuffer, 0, i);
}
} finally {
fis.close();
}
byte[] ba = baos.toByteArray();
return ba;
}
示例7: copyFiles
import java.io.FileInputStream; //导入方法依赖的package包/类
private void copyFiles(File from, File to) throws IOException {
LOG.fine("Copy " + from + " to " + to);
if (from.isDirectory()) {
to.mkdirs();
for (File f : from.listFiles()) {
copyFiles(f, new File(to, f.getName()));
}
} else {
byte[] arr = new byte[4096];
FileInputStream is = new FileInputStream(from);
FileOutputStream os = new FileOutputStream(to);
for (;;) {
int r = is.read(arr);
if (r == -1) {
break;
}
os.write(arr, 0, r);
}
is.close();
os.close();
}
}
示例8: testDataWriting
import java.io.FileInputStream; //导入方法依赖的package包/类
@Test
public void testDataWriting() throws Exception {
long byteAm = 100;
File fn = getTestFile();
DataWriter writer = new DataWriter(rnd);
FileOutputStream fs = new FileOutputStream(fn);
GenerateOutput ostat = writer.writeSegment(byteAm, fs);
LOG.info(ostat);
fs.close();
assertTrue(ostat.getBytesWritten() == byteAm);
DataVerifier vf = new DataVerifier();
FileInputStream fin = new FileInputStream(fn);
VerifyOutput vfout = vf.verifyFile(byteAm, new DataInputStream(fin));
LOG.info(vfout);
fin.close();
assertEquals(vfout.getBytesRead(), byteAm);
assertTrue(vfout.getChunksDifferent() == 0);
}
示例9: addFileToZip
import java.io.FileInputStream; //导入方法依赖的package包/类
static private void addFileToZip(String path, String srcFile, ZipOutputStream zip)
throws Exception {
File folder = new File(srcFile);
if (folder.isDirectory()) {
addFolderToZip(path, srcFile, zip);
} else {
byte[] buf = new byte[1024];
int len;
FileInputStream in = new FileInputStream(srcFile);
zip.putNextEntry(new ZipEntry(path + "/" + folder.getName()));
while ((len = in.read(buf)) > 0) {
zip.write(buf, 0, len);
}
in.close();
}
}
示例10: restoreFromCache
import java.io.FileInputStream; //导入方法依赖的package包/类
public Bitmap restoreFromCache(Card card, Cache cache) throws IOException {
String fileName = cache.getCacheLocation(getFileName(card));
FileInputStream in = context.openFileInput(fileName);
Bitmap out = BitmapFactory.decodeStream(in);
in.close();
return out;
}
示例11: parseFile
import java.io.FileInputStream; //导入方法依赖的package包/类
/**
* Parse the given configuration file
*
* @param configFile
* EncFS volume configuration file.
* @return An EncFSConfig object containing the configuration data
* interpreted from the given file.
*/
public static EncFSConfig parseFile(File configFile)
throws ParserConfigurationException, SAXException, IOException,
EncFSInvalidConfigException, EncFSUnsupportedException {
FileInputStream inputStream = new FileInputStream(configFile);
try {
return parseFile(inputStream);
} finally {
inputStream.close();
}
}
示例12: load
import java.io.FileInputStream; //导入方法依赖的package包/类
public static Player load(String playerName) throws IOException, ClassNotFoundException {
String filename = playerName + ".player";
Player player = null;
FileInputStream fileIn = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(fileIn);
player = (Player) in.readObject();
in.close();
fileIn.close();
logger.info("Loaded Player definition file from `" + filename + "`");
return player;
}
示例13: getAudioFileFormat
import java.io.FileInputStream; //导入方法依赖的package包/类
/**
* Obtains the audio file format of the File provided. The File must
* point to valid audio file data.
*
* @param file the File from which file format information should be
* extracted
* @return an <code>AudioFileFormat</code> object describing the audio file format
* @throws UnsupportedAudioFileException if the File does not point to valid audio
* file data recognized by the system
* @throws IOException if an I/O exception occurs
*/
public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException {
AudioFileFormat fileFormat = null;
FileInputStream fis = new FileInputStream(file); // throws IOException
// part of fix for 4325421
try {
fileFormat = getFMT(fis, false);
} finally {
fis.close();
}
return fileFormat;
}
示例14: getEditorInput
import java.io.FileInputStream; //导入方法依赖的package包/类
/**
* Generate Container from xml,Setting FileStorageEditor Input into Ifile
* @return Container
* @throws IOException
*/
@Override
public Container getEditorInput() throws IOException {
logger.debug("storeEditorInput - Setting FileStorageEditor Input into Ifile");
Container con = null;
File file = new File(fileStorageEditorInput.getToolTipText());
FileInputStream fs = new FileInputStream(file);
con = (Container) CanvasUtils.INSTANCE.fromXMLToObject(fs);
this.eltGraphicalEditorInstance.setPartName(file.getName());
fs.close();
return con;
}
示例15: WriteFile
import java.io.FileInputStream; //导入方法依赖的package包/类
public void WriteFile(File outputFile, int startFrame, int numFrames)
throws java.io.IOException {
outputFile.createNewFile();
FileInputStream in = new FileInputStream(mInputFile);
FileOutputStream out = new FileOutputStream(outputFile);
byte[] header = new byte[6];
header[0] = '#';
header[1] = '!';
header[2] = 'A';
header[3] = 'M';
header[4] = 'R';
header[5] = '\n';
out.write(header, 0, 6);
int maxFrameLen = 0;
for (int i = 0; i < numFrames; i++) {
if (mFrameLens[startFrame + i] > maxFrameLen)
maxFrameLen = mFrameLens[startFrame + i];
}
byte[] buffer = new byte[maxFrameLen];
int pos = 0;
for (int i = 0; i < numFrames; i++) {
int skip = mFrameOffsets[startFrame + i] - pos;
int len = mFrameLens[startFrame + i];
if (skip < 0) {
continue;
}
if (skip > 0) {
in.skip(skip);
pos += skip;
}
in.read(buffer, 0, len);
out.write(buffer, 0, len);
pos += len;
}
in.close();
out.close();
}