java.io.FileReader.close()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(197)

本文整理了Java中java.io.FileReader.close()方法的一些代码示例,展示了FileReader.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileReader.close()方法的具体详情如下:
包路径:java.io.FileReader
类名称:FileReader
方法名:close

FileReader.close介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-pinot

private boolean stopProcess(String fileName)
   throws IOException {
  File file = new File(fileName);
  FileReader reader = new FileReader(file);
  int pid = reader.read();

  Runtime.getRuntime().exec("kill " + pid);
  reader.close();

  file.delete();
  return true;
 }
}

代码示例来源:origin: android10/Android-CleanArchitecture

/**
 * Reads a content from a file.
 * This is an I/O operation and this method executes in the main thread, so it is recommended to
 * perform the operation using another thread.
 *
 * @param file The file to read from.
 * @return A string with the content of the file.
 */
String readFileContent(File file) {
 final StringBuilder fileContentBuilder = new StringBuilder();
 if (file.exists()) {
  String stringLine;
  try {
   final FileReader fileReader = new FileReader(file);
   final BufferedReader bufferedReader = new BufferedReader(fileReader);
   while ((stringLine = bufferedReader.readLine()) != null) {
    fileContentBuilder.append(stringLine).append("\n");
   }
   bufferedReader.close();
   fileReader.close();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
 return fileContentBuilder.toString();
}

代码示例来源:origin: stanfordnlp/CoreNLP

public void readGrammar(String filename) {
 try {
  FileReader fin = new FileReader(filename);
  BufferedReader bin = new BufferedReader(fin);
  readGrammar(bin);
  bin.close();
  fin.close();
 } catch (IOException e) {
  throw new RuntimeIOException(e);
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

FileReader fr = new FileReader(etcResolvConf);
BufferedReader br = null;
try {
  br = new BufferedReader(fr);
  String line;
  while ((line = br.readLine()) != null) {
    if (line.startsWith(OPTIONS_ROW_LABEL)) {
      int i = line.indexOf(NDOTS_LABEL);
    fr.close();
  } else {
    br.close();

代码示例来源:origin: gocd/gocd

public ArtifactMd5Checksums(File checksumProperties) {
  this.checksumProperties = new Properties();
  FileReader fileReader = null;
  BufferedReader reader = null;
  try {
    fileReader = new FileReader(checksumProperties);
    reader = new BufferedReader(fileReader);
    this.checksumProperties.load(reader);
  } catch (IOException e) {
    throw new RuntimeException(String.format("[Checksum Verification] Could not load the MD5 from the checksum file '%s'", checksumProperties), e);
  } finally {
    if (reader != null) {
      try {
        reader.close();
      } catch (IOException e) {
        LOGGER.warn("Failed to close buffered reader for checksum file: {}", checksumProperties.getAbsolutePath(), e);
      }
    }
    if (fileReader != null) {
      try {
        fileReader.close();
      } catch (IOException e) {
        LOGGER.warn("Failed to close file-reader for checksum file: {}", checksumProperties.getAbsolutePath(), e);
      }
    }
  }
}

代码示例来源:origin: h2oai/h2o-2

private String readFile(File f) throws Exception {
 char[] buffer = new char[16 * 1024];
 FileReader fr = new FileReader(f);
 int bytesRead = 0;
 while (true) {
  int n = fr.read(buffer, bytesRead, buffer.length - bytesRead);
  if (n < 0) {
   fr.close();
   return new String (buffer, 0, bytesRead);
  }
  else if (n == 0) {
   // This is weird.
   fr.close();
   throw new Exception("LinuxProcFileReader readFile read 0 bytes");
  }
  bytesRead += n;
  if (bytesRead >= buffer.length) {
   fr.close();
   throw new Exception("LinuxProcFileReader readFile unexpected buffer full");
  }
 }
}

代码示例来源:origin: mcxiaoke/packer-ng-plugin

public static Set<String> parseChannels(final File file) throws IOException {
  final List<String> channels = new ArrayList<>();
  FileReader fr = new FileReader(file);
  BufferedReader br = new BufferedReader(fr);
  String line;
  while ((line = br.readLine()) != null) {
    String parts[] = line.split("#");
    if (parts.length > 0) {
      final String ch = parts[0].trim();
      if (ch.length() > 0) {
        channels.add(ch);
      }
    }
  }
  br.close();
  fr.close();
  return escape(channels);
}

代码示例来源:origin: javax.activation/activation

/**
 * The construtor that takes a filename as an argument.
 *
 * @param new_fname The file name of the mime types file.
 */
public MimeTypeFile(String new_fname) throws IOException {
File mime_file = null;
FileReader fr = null;
fname = new_fname; // remember the file name
mime_file = new File(fname); // get a file object
fr = new FileReader(mime_file);
try {
  parse(new BufferedReader(fr));
} finally {
  try {
  fr.close(); // close it
  } catch (IOException e) {
  // ignore it
  }
}
}

代码示例来源:origin: voldemort/voldemort

public List<StoreDefinition> readStoreList(File f) throws IOException {
  FileReader reader = null;
  try {
    reader = new FileReader(f);
    return readStoreList(reader);
  } finally {
    if(reader != null)
      reader.close();
  }
}

代码示例来源:origin: redisson/redisson

FileReader fr = new FileReader(etcResolvConf);
BufferedReader br = null;
try {
  br = new BufferedReader(fr);
  String line;
  while ((line = br.readLine()) != null) {
    if (line.startsWith(OPTIONS_ROW_LABEL)) {
      int i = line.indexOf(NDOTS_LABEL);
    fr.close();
  } else {
    br.close();

代码示例来源:origin: javax.activation/activation

/**
 * The constructor that takes a filename as an argument.
 *
 * @param new_fname The file name of the mailcap file.
 */
public MailcapFile(String new_fname) throws IOException {
if (LogSupport.isLoggable())
  LogSupport.log("new MailcapFile: file " + new_fname);
FileReader reader = null;
try {
  reader = new FileReader(new_fname);
  parse(new BufferedReader(reader));
} finally {
  if (reader != null) {
  try {
    reader.close();
  } catch (IOException ex) { }
  }
}
}

代码示例来源:origin: voldemort/voldemort

public Cluster readCluster(File f) throws IOException {
  FileReader reader = null;
  try {
    reader = new FileReader(f);
    return readCluster(reader);
  } finally {
    if(reader != null)
      reader.close();
  }
}

代码示例来源:origin: menacher/java-game-server

public static String readSmallFile(File smallFile)
      throws IOException
  {
    FileReader reader = new FileReader(smallFile);
    BufferedReader bufferedReader = new BufferedReader(reader);
    StringBuffer buf = new StringBuffer();
    String line = null;
    while ((line = bufferedReader.readLine()) != null)
    {
      buf.append(line);
    }
    bufferedReader.close();
    reader.close();
    return buf.toString();
  }
}

代码示例来源:origin: pentaho/mondrian

protected void commandLoop(File file) throws IOException {
  // If we open a stream, then we close it.
  FileReader in = new FileReader(file);
  try {
    commandLoop(new BufferedReader(in), false);
  } finally {
    try {
      in.close();
    } catch (Exception ex) {
      // ignore
    }
  }
}

代码示例来源:origin: apache/geode

public static List<ClassAndMethodDetails> loadClassesAndMethods(File file) throws IOException {
 List<ClassAndMethodDetails> result = new LinkedList<ClassAndMethodDetails>();
 FileReader fr = new FileReader(file);
 LineNumberReader in = new LineNumberReader(fr);
 ClassAndMethodDetails cam;
 while ((cam = ClassAndMethodDetails.create(in)) != null) {
  result.add(cam);
 }
 fr.close();
 return result;
}

代码示例来源:origin: apache/geode

private List<String> loadExcludedClasses(File exclusionsFile) throws IOException {
 List<String> excludedClasses = new LinkedList<>();
 FileReader fr = new FileReader(exclusionsFile);
 BufferedReader br = new BufferedReader(fr);
 try {
  String line;
  while ((line = br.readLine()) != null) {
   line = line.trim();
   if (!line.isEmpty() && !line.startsWith("#")) {
    excludedClasses.add(line);
   }
  }
 } finally {
  fr.close();
 }
 return excludedClasses;
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * The construtor that takes a filename as an argument.
 *
 * @param new_fname The file name of the mime types file.
 */
public MimeTypeFile(String new_fname) throws IOException {
File mime_file = null;
FileReader fr = null;
fname = new_fname; // remember the file name
mime_file = new File(fname); // get a file object
fr = new FileReader(mime_file);
try {
  parse(new BufferedReader(fr));
} finally {
  try {
  fr.close(); // close it
  } catch (IOException e) {
  // ignore it
  }
}
}

代码示例来源:origin: spotbugs/spotbugs

public static HashSet getWordSet(File wordfile) throws IOException {
  HashSet result = new HashSet();
  FileReader reader = null;
  try {
    reader = new FileReader(wordfile);
    result = getWordSet(reader);
  } finally {
    if (reader != null)
      reader.close();
  }
  return result;
}

代码示例来源:origin: NanoHttpd/nanohttpd

BufferedReader reader = null;
try {
  fileReader = new FileReader(file);
  reader = new BufferedReader(fileReader);
  String line = null;
  StringBuilder sb = new StringBuilder();
  do {
    line = reader.readLine();
    if (line != null) {
      sb.append(line).append("\n");
  try {
    if (fileReader != null) {
      fileReader.close();

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * The constructor that takes a filename as an argument.
 *
 * @param new_fname The file name of the mailcap file.
 */
public MailcapFile(String new_fname) throws IOException {
if (LogSupport.isLoggable())
  LogSupport.log("new MailcapFile: file " + new_fname);
FileReader reader = null;
try {
  reader = new FileReader(new_fname);
  parse(new BufferedReader(reader));
} finally {
  if (reader != null) {
  try {
    reader.close();
  } catch (IOException ex) { }
  }
}
}

相关文章