當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。