本文整理汇总了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;
}