本文整理匯總了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();
}
}
示例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();
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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)));
}
示例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();
}
示例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;
}
示例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 = "";
}
}
示例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);
}
}
示例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;
}