当前位置: 首页>>代码示例>>Java>>正文


Java FileInputStream类代码示例

本文整理汇总了Java中java.io.FileInputStream的典型用法代码示例。如果您正苦于以下问题:Java FileInputStream类的具体用法?Java FileInputStream怎么用?Java FileInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileInputStream类属于java.io包,在下文中一共展示了FileInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readTestObject

import java.io.FileInputStream; //导入依赖的package包/类
private DecimalFormatSymbols readTestObject(File inputFile){
    try (InputStream istream = inputFile.getName().endsWith(".txt") ?
                                   HexDumpReader.getStreamFromHexDump(inputFile) :
                                   new FileInputStream(inputFile)) {
        ObjectInputStream p = new ObjectInputStream(istream);
        DecimalFormatSymbols dfs = (DecimalFormatSymbols)p.readObject();
        return dfs;
    } catch (Exception e) {
        errln("Test Malfunction in DFSSerialization: Exception while reading the object");
        /*
         * logically should not throw this exception as errln throws exception
         * if not thrown yet - but in case errln got changed
         */
        throw new RuntimeException("Test Malfunction: re-throwing the exception", e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:DFSSerialization.java

示例2: usage1

import java.io.FileInputStream; //导入依赖的package包/类
public void usage1(String inputFile) throws FileNotFoundException {
   Velocity.init();

    VelocityContext context = new VelocityContext();

    context.put("author", "Elliot A.");
    context.put("address", "217 E Broadway");
    context.put("phone", "555-1337");

    FileInputStream file = new FileInputStream(inputFile);

    //Evaluate
    StringWriter swOut = new StringWriter();
    Velocity.evaluate(context, swOut, "test", file);

    String result =  swOut.getBuffer().toString();
    System.out.println(result);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:19,代码来源:VelocityUsage.java

示例3: load

import java.io.FileInputStream; //导入依赖的package包/类
/**
 * 根据文件解码一个新nmap对象
 * @param file
 * @return
 * @throws Exception
 */
public final NMap load(File file) throws Exception
{
	if(file.exists())
	{
		FileInputStream fis=new FileInputStream(file);
		BufferedInputStream bis=new BufferedInputStream(fis);
		ByteArrayOutputStream bos=new ByteArrayOutputStream();//定义一个内存输出流
		int i=-1;
		while(true)
		{
			i=bis.read();
			if(i==-1)
			{
				break;
			}
			bos.write(i);//保存到内存数组
		}
		bos.flush();
		bos.close();
		bis.close();
		return (NMap) decoder(bos.toByteArray());
	}
	return null;
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:31,代码来源:NMap.java

示例4: testStoreTemporaryBarFile2

import java.io.FileInputStream; //导入依赖的package包/类
/**
 * fsync OFF.
 * FileDescriptor#sync() should never be called.
 * @throws Exception .
 */
@Test
public void testStoreTemporaryBarFile2() throws Exception {
    boolean fsyncEnabled = PersoniumUnitConfig.getFsyncEnabled();
    PersoniumUnitConfig.set(BinaryData.FSYNC_ENABLED, "false");
    try {
        CellEsImpl cell = new CellEsImpl();
        cell.setId("hogeCell");
        BarFileInstaller bfi = Mockito.spy(new BarFileInstaller(cell, "hogeBox", null, null));
        Method method = BarFileInstaller.class.getDeclaredMethod(
                "storeTemporaryBarFile", new Class<?>[] {InputStream.class});
        method.setAccessible(true);
        //any file
        method.invoke(bfi, new FileInputStream("pom.xml"));
        Mockito.verify(bfi, Mockito.never()).sync((FileDescriptor) Mockito.anyObject());
    } finally {
        PersoniumUnitConfig.set(BinaryData.FSYNC_ENABLED, String.valueOf(fsyncEnabled));
    }
}
 
开发者ID:personium,项目名称:personium-core,代码行数:24,代码来源:BarFileValidateTest.java

示例5: getAsStream

import java.io.FileInputStream; //导入依赖的package包/类
/**
 * Loads a resource and returns an InputStream to it.
 *
 * @param name
 * @return
 */
public static InputStream getAsStream(String name) {
    if (name == null) {
        return null;
    }
    
    try {
        URL url = getAsURL(name);
        if (url == null) {
            File file = new File(name);
            if (file.exists()) {
                return new FileInputStream(file);
            }
            return null;
        } else {
            return url.openStream();
        }
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:Anoncheg1,项目名称:dibd,代码行数:28,代码来源:Resource.java

示例6: copyFile

import java.io.FileInputStream; //导入依赖的package包/类
public static void copyFile(File sourceFile, File targetFile)
		throws IOException {
	// 新建文件输入流并对它进行缓冲
	FileInputStream input = new FileInputStream(sourceFile);
	BufferedInputStream inBuff = new BufferedInputStream(input);

	// 新建文件输出流并对它进行缓冲
	FileOutputStream output = new FileOutputStream(targetFile);
	BufferedOutputStream outBuff = new BufferedOutputStream(output);

	// 缓冲数组
	byte[] b = new byte[1024 * 5];
	int len;
	while ((len = inBuff.read(b)) != -1) {
		outBuff.write(b, 0, len);
	}
	// 刷新此缓冲的输出流
	outBuff.flush();

	//关闭流
	inBuff.close();
	outBuff.close();
	output.close();
	input.close();
}
 
开发者ID:G2159687,项目名称:ESPD,代码行数:26,代码来源:FileOperations.java

示例7: enfile_read

import java.io.FileInputStream; //导入依赖的package包/类
public static String enfile_read(String file_name, byte[] key) throws Exception {
    file = new File(file_name);
    bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
    
    secretKey = new SecretKeySpec(key, "AES");
    cipher = Cipher.getInstance(CIPHER_ALOGORTHM);
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    cipherInputStream = new CipherInputStream(bufferedInputStream, cipher);

    String str = "";

    while((length = cipherInputStream.read(cache)) > 0) {
        str += new String(cache, 0, length);
    }
    return str;
}
 
开发者ID:48763,项目名称:File-Cipher,代码行数:17,代码来源:FileCipherStream.java

示例8: testUpload

import java.io.FileInputStream; //导入依赖的package包/类
@Test
public void testUpload() throws Exception {

    expectNew(org.apache.commons.net.ftp.FTPClient.class).andReturn(mockFtp);

    mockFtp.setConnectTimeout(DEFAULT_TIMEOUT);
    mockFtp.connect(HOSTNAME, PORT_NUMBER);
    mockFtp.setAutodetectUTF8(false);
    EasyMock.expectLastCall().once();
    expect(mockFtp.login(USERNAME, PASSWORD)).andReturn(true);
    mockFtp.enterLocalPassiveMode();
    expect(mockFtp.setFileType(org.apache.commons.net.ftp.FTPClient.BINARY_FILE_TYPE)).andReturn(true);

    expect(mockFtp.storeFile(eq(REMOTE_DIRECTORY_NAME + "/" + REMOTE_FILE_NAME),
                             isA(FileInputStream.class))).andReturn(true);

    expect(mockFtp.getPassiveHost()).andReturn(HOSTNAME);

    replayAll();

    testObject.connect(HOSTNAME, USERNAME, PASSWORD);
    testObject.uploadFile(LOCAL_FILE_NAME, REMOTE_DIRECTORY_NAME, REMOTE_FILE_NAME);

    verifyAll();
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:26,代码来源:Test_FTPClient.java

示例9: importBlocks

import java.io.FileInputStream; //导入依赖的package包/类
@Test
@Ignore
public void importBlocks() throws Exception {
    Logger logger = LoggerFactory.getLogger("VM");
    logger.info("#######################################");
    BlockchainImpl blockchain = createBlockchain(GenesisLoader.loadGenesis(
            getClass().getResourceAsStream("/genesis/frontier.json")));
    Scanner scanner = new Scanner(new FileInputStream("D:\\ws\\ethereumj\\work\\blocks-rec.dmp"));
    while (scanner.hasNext()) {
        String blockHex = scanner.next();
        Block block = new Block(Hex.decode(blockHex));
        ImportResult result = blockchain.tryToConnect(block);
        if (result != ImportResult.EXIST && result != ImportResult.IMPORTED_BEST) {
            throw new RuntimeException(result + ": " + block + "");
        }
        System.out.println("Imported " + block.getShortDescr());
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:19,代码来源:ImportLightTest.java

示例10: copyFileOntoRemovableStorage

import java.io.FileInputStream; //导入依赖的package包/类
static boolean copyFileOntoRemovableStorage(Context context, Uri treeUri,
                                            String path, String destination) throws IOException {
    String mimeType = MediaType.getMimeType(path);
    DocumentFile file = DocumentFile.fromFile(new File(destination));
    if (file.exists()) {
        int index = destination.lastIndexOf(".");
        destination = destination.substring(0, index) + " Copy"
                + destination.substring(index, destination.length());
    }
    DocumentFile destinationFile = StorageUtil.createDocumentFile(context, treeUri, destination, mimeType);

    if (destinationFile != null) {
        ContentResolver resolver = context.getContentResolver();
        OutputStream outputStream = resolver.openOutputStream(destinationFile.getUri());
        InputStream inputStream = new FileInputStream(path);
        return writeStream(inputStream, outputStream);
    }
    return false;
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:20,代码来源:Copy.java

示例11: compareFiles

import java.io.FileInputStream; //导入依赖的package包/类
/**
 * Compare the data contents of two files.
 *
 * @param file1 the first file to compare
 * @param file2 the second file to compare
 * @return true if the files have the same content and length
 * @throws IOException if a java.io operation throws
 */
public boolean compareFiles(File file1, File file2) throws IOException {

    if (file1.length() != file2.length()) {
        return false;
    }

    InputStream in1 = new FileInputStream(file1);
    InputStream in2 = new FileInputStream(file2);
    for (;;) {
        int ch1 = in1.read();
        if (ch1 == -1) {
            break;
        }
        int ch2 = in2.read();
        if (ch1 != ch2) {
            in1.close();
            in2.close();
            return false;
        }
    }

    in1.close();
    in2.close();
    return true;
}
 
开发者ID:klamonte,项目名称:jermit,代码行数:34,代码来源:SerialTransferTest.java

示例12: addMappings

import java.io.FileInputStream; //导入依赖的package包/类
private void addMappings(Map<String, Map<String, Object>> mappings, File mappingsDir) {
    File[] mappingsFiles = mappingsDir.listFiles();
    for (File mappingFile : mappingsFiles) {
        if (mappingFile.isHidden()) {
            continue;
        }
        int lastDotIndex = mappingFile.getName().lastIndexOf('.');
        String mappingType = lastDotIndex != -1 ? mappingFile.getName().substring(0, lastDotIndex) : mappingFile.getName();
        try {
            String mappingSource = Streams.copyToString(new InputStreamReader(new FileInputStream(mappingFile), Charsets.UTF_8));
            if (mappings.containsKey(mappingType)) {
                XContentHelper.mergeDefaults(mappings.get(mappingType), parseMapping(mappingSource));
            } else {
                mappings.put(mappingType, parseMapping(mappingSource));
            }
        } catch (Exception e) {
            logger.warn("failed to read / parse mapping [" + mappingType + "] from location [" + mappingFile + "], ignoring...", e);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:TransportBulkCreateIndicesAction.java

示例13: read

import java.io.FileInputStream; //导入依赖的package包/类
/**
 * @return null if we were unable to load the cached version
 */
public GrammaticalLabelSetImpl read() {
    // if we're tracking duplicated labels, we need to load the file directly in order to look at all the labels, so don't load from the cache
    if (this.language == LanguageProviderFactory.get().getBaseLanguage() && GrammaticalLabelFileParser.isDupeLabelTrackingEnabled()) {
        return null;
    }

    logger.info("Loading " + labelSetName + " from cache");
    long start = System.currentTimeMillis();
    try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(this.cacheFile))) {
        GrammaticalLabelSetImpl labelSet = (GrammaticalLabelSetImpl)ois.readObject();
        logger.info("Loaded " + this.labelSetName + " from cache in " + (System.currentTimeMillis() - start)
            + " ms");
        return labelSet;
    }
    catch (Exception e) {
        logger.log(Level.INFO, "Could not load " + labelSetName + " from cache: ", e);
        delete();
    }
    return null;
}
 
开发者ID:salesforce,项目名称:grammaticus,代码行数:24,代码来源:GrammaticalLabelSetFileCacheLoader.java

示例14: restoreState

import java.io.FileInputStream; //导入依赖的package包/类
public final void restoreState(String slot) throws IOException, ClassNotFoundException{
	if(!nsfplayer){
	FileInputStream fin = new FileInputStream(slot);
	ObjectInputStream in = new ObjectInputStream(fin);
	pause = true;
	try {
		Thread.sleep(20);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	map = (Mapper) in.readObject();
	map.apu = (APU) in.readObject();
	map.cpu = (CPU_6502) in.readObject();
	map.ppu = (ppu2C02) in.readObject();
	map.setSystem(system);
	in.close();
	pause = false;
	}
}
 
开发者ID:QuantumSoundings,项目名称:BassNES,代码行数:20,代码来源:NES.java

示例15: loadOptionProperties

import java.io.FileInputStream; //导入依赖的package包/类
private static Properties loadOptionProperties(IShaderPack sp) throws IOException
{
    Properties properties = new Properties();
    String s = shaderpacksdirname + "/" + sp.getName() + ".txt";
    File file1 = new File(Minecraft.getMinecraft().mcDataDir, s);

    if (file1.exists() && file1.isFile() && file1.canRead())
    {
        FileInputStream fileinputstream = new FileInputStream(file1);
        properties.load((InputStream)fileinputstream);
        fileinputstream.close();
        return properties;
    }
    else
    {
        return properties;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:19,代码来源:Shaders.java


注:本文中的java.io.FileInputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。