當前位置: 首頁>>代碼示例>>Java>>正文


Java FileReader.close方法代碼示例

本文整理匯總了Java中java.io.FileReader.close方法的典型用法代碼示例。如果您正苦於以下問題:Java FileReader.close方法的具體用法?Java FileReader.close怎麽用?Java FileReader.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.FileReader的用法示例。


在下文中一共展示了FileReader.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readFile

import java.io.FileReader; //導入方法依賴的package包/類
/**
 * Method declaration
 * Redid this file to remove sizing requirements and to make it faster
 * Speeded it up 10 fold.
 * @param file
 * @return
 */
static String readFile(String file) {

    try {
        FileReader     reader = new FileReader(file);
        BufferedReader read   = new BufferedReader(reader);
        StringBuffer   b      = new StringBuffer();
        String         s      = null;
        int            count  = 0;

        while ((s = read.readLine()) != null) {
            count++;

            b.append(s);
            b.append('\n');
        }

        read.close();
        reader.close();

        return b.toString();
    } catch (IOException e) {
        return e.getMessage();
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:32,代碼來源:DatabaseManagerCommon.java

示例2: areFilesIdentical

import java.io.FileReader; //導入方法依賴的package包/類
/** byte-by-byte comparison of two files. Returns true if they are identical */
//@TODO, if these is used to compare text files, we should ignore line endings!
public static boolean areFilesIdentical(File f1, File f2) throws Exception {
    if (!f1.exists() || !f2.exists())
        return false;
    
    FileReader fr1 = new FileReader(f1);
    FileReader fr2 = new FileReader(f2);
    try {
        long counter=0;
        int x,y;
        do {
            counter++;
            x=fr1.read();
            y=fr2.read();
            if(x==y && x==-1)
                return true;
        } while(x==y);
        log.error("File compare failed at byte " + counter);
        return false;
    } finally {
        fr1.close();
        fr2.close();
    }
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:26,代碼來源:UnitTestUtil.java

示例3: getFileContent

import java.io.FileReader; //導入方法依賴的package包/類
/**
 * 讀取文件的內容
 * 讀取指定文件的內容
 * @param path 為要讀取文件的絕對路徑
 * @return 以行讀取文件後的內容。
 * @since  1.0
 */
public static final String getFileContent(String path) throws IOException
{
  String filecontent = "";
  try {
    File f = new File(path);
    if (f.exists()) {
      FileReader fr = new FileReader(path);
      BufferedReader br = new BufferedReader(fr); //建立BufferedReader對象,並實例化為br
      String line = br.readLine(); //從文件讀取一行字符串
      //判斷讀取到的字符串是否不為空
      while (line != null) {
        filecontent += line + "\n";
        line = br.readLine(); //從文件中繼續讀取一行數據
      }
      br.close(); //關閉BufferedReader對象
      fr.close(); //關閉文件
    }

  }
  catch (IOException e) {
    throw e;
  }
  return filecontent;
}
 
開發者ID:huangjiaqian,項目名稱:wbczq,代碼行數:32,代碼來源:FileUtil.java

示例4: initial

import java.io.FileReader; //導入方法依賴的package包/類
public static boolean  initial() throws Exception{
	if(scheduleManagerFactory != null){
		return true;
	}
	File file = new File(configFile);
	scheduleManagerFactory = new TBScheduleManagerFactory();
	scheduleManagerFactory.start = false;
	
	if(file.exists() == true){
		//Console不啟動調度能力
		Properties p = new Properties();
		FileReader reader = new FileReader(file);
		p.load(reader);
		reader.close();
		scheduleManagerFactory.init(p);
		log.info("加載Schedule配置文件:" +configFile );
		return true;
	}else{
		return false;
	}
}
 
開發者ID:hungki,項目名稱:tbschedule-wed,代碼行數:22,代碼來源:ConsoleManager.java

示例5: loadSimSetup

import java.io.FileReader; //導入方法依賴的package包/類
/**
 * Loads the simulation setup with the specified name
 * @param setupName The setup to be loaded
 * @return The setup
 * @throws JAXBException Parsing the setup file failed
 * @throws IOException Reading the setup file failed
 */
private SimulationSetup loadSimSetup(String setupName) throws JAXBException, IOException {
	// --- Determine the setup file path ----------
	String setupFileName = this.project.getSimulationSetups().get(setupName);
	String setupFileFullPath = this.project.getSubFolder4Setups(true) + File.separator + setupFileName;
	File setupFile = new File(setupFileFullPath);

	// --- Load the setup -------------
	JAXBContext pc;
	SimulationSetup simSetup = null;
	pc = JAXBContext.newInstance(this.project.getSimulationSetups().getCurrSimSetup().getClass());
	Unmarshaller um = pc.createUnmarshaller();
	FileReader fr = new FileReader(setupFile);
	simSetup = (SimulationSetup) um.unmarshal(fr);
	fr.close();

	return simSetup;

}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:26,代碼來源:ProjectExportController.java

示例6: loadNodeViewersFile

import java.io.FileReader; //導入方法依賴的package包/類
public List<String> loadNodeViewersFile(File selectedFile)
        throws IOException {
    List<String> result = new ArrayList<String>();
    if (defaultNodeViewersFile.exists()) {
        FileReader reader = new FileReader(selectedFile);
        try {
            BufferedReader buff = new BufferedReader(reader);
            try {
                while (buff.ready()) {
                    String line = buff.readLine();
                    if (line != null && line.length() > 0 && !line.startsWith("#")) {
                        result.add(line);
                    }
                }
            } finally {
                buff.close();
            }
        } finally {
            reader.close();
        }
    }
    return result;
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:24,代碼來源:ZooInspectorManagerImpl.java

示例7: loadStringsFromFile

import java.io.FileReader; //導入方法依賴的package包/類
/**
 * Loads a list of newline-separated strings into a new HashSet and returns
 * the HashSet.
 *
 * @param filename filename to process
 * @return set of all unique lines in the file
 */
private static HashSet<String> loadStringsFromFile(String filename) {
    HashSet<String> result = new HashSet<String>();

    try {
        FileReader fr = new FileReader(filename);
        BufferedReader bfr = new BufferedReader(fr);

        String line;

        while (null != (line = bfr.readLine())) {
            result.add(line);
        }

        fr.close();
    } catch (IOException ex) {
        // Let the exception percolate up as a RuntimeException.
        throw new RuntimeException("Error with optimize list: " +
                filename, ex);
    }

    return result;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:30,代碼來源:OptimizerOptions.java

示例8: main

import java.io.FileReader; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
    String alphabetL = "abcdefghijklmnopqrstuvwxyz";
    String alphabetH = alphabetL.toUpperCase();

    FileReader f = new FileReader(args[0]);

    int count = 0;
    while (f.ready()) {
        char s = (char) f.read();
        if ((alphabetL.indexOf(s) > -1) || alphabetH.indexOf(s) > -1)
            count++;
    }
    f.close();

    System.out.println(count);

}
 
開發者ID:avedensky,項目名稱:JavaRushTasks,代碼行數:18,代碼來源:Solution.java

示例9: restore

import java.io.FileReader; //導入方法依賴的package包/類
private void restore() {
    File file = new File(Environment.getExternalStorageDirectory()+"/save-compass-1.txt");
    try {
        FileReader f = new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(f);
        String line;
        if ((line = bufferedReader.readLine()) != null) {
            O1X = Float.parseFloat(line.trim());
            if ((line = bufferedReader.readLine()) != null) {
                O1Y = Float.parseFloat(line.trim());
            }
            if ((line = bufferedReader.readLine()) != null) {
                O1A = Float.parseFloat(line.trim());
            }
            if ((line = bufferedReader.readLine()) != null) {
                O2X = Float.parseFloat(line.trim());
            }
            if ((line = bufferedReader.readLine()) != null) {
                O2Y = Float.parseFloat(line.trim());
            }
            if ((line = bufferedReader.readLine()) != null) {
                O2A = Float.parseFloat(line.trim());
            }
        }
        bufferedReader.close();
        f.close();
    } catch (IOException e) {
        warn("無法從 save-compass-1.txt 讀取資料", 0);
    }
}
 
開發者ID:wade-fs,項目名稱:Military-North-Compass,代碼行數:31,代碼來源:Compass.java

示例10: writeReadTest

import java.io.FileReader; //導入方法依賴的package包/類
@Test
public void writeReadTest() throws IOException {
  File ini = testFolder.newFile();
  FileWriter out = new FileWriter(ini);
  config1.write(out);
  out.close();

  FileReader in = new FileReader(ini);
  EncryptionConfig config2 = new EncryptionConfigBuilder().readFromFile(in).build();
  in.close();

  assertThat("writing then reading the config should produce an equivalent configuration", config2, is(equalTo(config1)));
}
 
開發者ID:mit-ll,項目名稱:PACE,代碼行數:14,代碼來源:EncryptionConfigTest.java

示例11: openMappings

import java.io.FileReader; //導入方法依賴的package包/類
public void openMappings(File file) throws IOException, MappingParseException {
	FileReader in = new FileReader(file);
	m_deobfuscator.setMappings(new MappingsReader().read(in));
	in.close();
	m_isDirty = false;
	m_gui.setMappingsFile(file);
	markWords();
	refreshCurrentClass();
}
 
開發者ID:cccssw,項目名稱:enigma-vk,代碼行數:10,代碼來源:GuiController.java

示例12: readLogUser

import java.io.FileReader; //導入方法依賴的package包/類
public static boolean readLogUser(){
    boolean logUser = false;
    File configFile = new File("config.properties");
    try{
        FileReader reader = new FileReader(configFile);
        Properties props = new Properties();
        props.load(reader);
        logUser = Boolean.parseBoolean(props.getProperty("LogUserMessages"));
        reader.close();
    } catch (IOException e){
        e.printStackTrace();
    }
    return logUser;
}
 
開發者ID:franziheck,項目名稱:Paulette,代碼行數:15,代碼來源:PropsHandler.java

示例13: loadDefaultConnectionFile

import java.io.FileReader; //導入方法依賴的package包/類
private void loadDefaultConnectionFile() throws IOException {
    if (defaultConnectionFile.exists()) {
        Properties props = new Properties();

        FileReader reader = new FileReader(defaultConnectionFile);
        try {
            props.load(reader);
        } finally {
            reader.close();
        }
        defaultEncryptionManager = props
                .getProperty(DATA_ENCRYPTION_MANAGER) == null ? "org.apache.zookeeper.inspector.encryption.BasicDataEncryptionManager"
                : props.getProperty(DATA_ENCRYPTION_MANAGER);
        defaultTimeout = props.getProperty(SESSION_TIMEOUT) == null ? "5000"
                : props.getProperty(SESSION_TIMEOUT);
        defaultHosts = props.getProperty(CONNECT_STRING) == null ? "localhost:2181"
                : props.getProperty(CONNECT_STRING);
        defaultAuthScheme = props.getProperty(AUTH_SCHEME_KEY) == null ? ""
                : props.getProperty(AUTH_SCHEME_KEY);
        defaultAuthValue = props.getProperty(AUTH_DATA_KEY) == null ? ""
                : props.getProperty(AUTH_DATA_KEY);
    } else {
        defaultEncryptionManager = "org.apache.zookeeper.inspector.encryption.BasicDataEncryptionManager";
        defaultTimeout = "5000";
        defaultHosts = "localhost:2181";
        defaultAuthScheme = "";
        defaultAuthValue = "";
    }
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:30,代碼來源:ZooInspectorManagerImpl.java

示例14: restore

import java.io.FileReader; //導入方法依賴的package包/類
private void restore() {
    File file = new File(Environment.getExternalStorageDirectory()+"/save-compass-2.txt");
    try {
        FileReader f = new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(f);
        String line;
        if ((line = bufferedReader.readLine()) != null) {
            mainActivity.A.x = Float.parseFloat(line.trim());
            if ((line = bufferedReader.readLine()) != null) {
                mainActivity.A.y = Float.parseFloat(line.trim());
            }
            if ((line = bufferedReader.readLine()) != null) {
                mainActivity.angleA = Float.parseFloat(line.trim());
            }
            if ((line = bufferedReader.readLine()) != null) {
                mainActivity.B.x = Float.parseFloat(line.trim());
            }
            if ((line = bufferedReader.readLine()) != null) {
                mainActivity.B.y = Float.parseFloat(line.trim());
            }
            if ((line = bufferedReader.readLine()) != null) {
                mainActivity.angleB = Float.parseFloat(line.trim());
            }
        }
        bufferedReader.close();
        f.close();
    } catch (IOException e) {
        warn("無法從 save-compass-2.txt 讀取資料", 0);
    }
}
 
開發者ID:wade-fs,項目名稱:Military-North-Compass,代碼行數:31,代碼來源:TriangleView.java

示例15: readMnMaskFile

import java.io.FileReader; //導入方法依賴的package包/類
private ArrayList<MnPoint> readMnMaskFile(File maskFile) {
    ArrayList<MnPoint> mnPoints = new ArrayList<MnPoint>();

    try {
        FileReader fileReader = new FileReader(maskFile);
        BufferedReader inputFileBufferedReader = new BufferedReader(fileReader);

        String line = inputFileBufferedReader.readLine();
        while (line != null) {
            String trimmedLine = line.trim();
            if ( !trimmedLine.startsWith("#") && !(trimmedLine.length() == 0) ) {
                String[] fields = trimmedLine.split("[\t ]*,[\t ]*");
                if (fields.length != 2) {
                    throw new RuntimeException("Invalid line \n\t\"" + line + "\"\nin mask file " + maskFile.getAbsolutePath());
                }
                mnPoints.add(new MnPoint(fields[0], fields[1]));

            }
            line = inputFileBufferedReader.readLine();
        }

        inputFileBufferedReader.close();
        fileReader.close();
    } catch (IOException e) {
        throw new RuntimeException("Error when reading: "  + maskFile.getAbsolutePath() + ": " + e.getMessage());
    }

    return mnPoints;
}
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:30,代碼來源:D3dWindMask.java


注:本文中的java.io.FileReader.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。