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

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

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

FileReader.<init>介绍

[英]Constructs a new FileReader on the given file.
[中]在给定文件上构造新的FileReader。

代码示例

代码示例来源:origin: stackoverflow.com

try {
  BufferedReader br = new BufferedReader(new FileReader(inputFile));
  ...
  ...
} catch (Exception e) {
  e.printStacktrace();
}

代码示例来源:origin: stackoverflow.com

try(BufferedReader br = new BufferedReader(new FileReader(file))) {
  for(String line; (line = br.readLine()) != null; ) {
    // process the line.
  }
  // line is not visible here.
}

代码示例来源:origin: iluwatar/java-design-patterns

/**
 * Loads the data of the file specified.
 */
public String loadData() {
 String dataFileName = this.fileName;
 try (BufferedReader br = new BufferedReader(new FileReader(new File(dataFileName)))) {
  StringBuilder sb = new StringBuilder();
  String line;
  while ((line = br.readLine()) != null) {
   sb.append(line).append('\n');
  }
  this.loaded = true;
  return sb.toString();
 } catch (Exception e) {
  LOGGER.error("File {} does not exist", dataFileName);
 }
 return null;
}

代码示例来源:origin: brianfrankcooper/YCSB

/**
  * Reopen the file to reuse values.
  */
 public synchronized void reloadFile() {
  try (Reader r = reader) {
   System.err.println("Reload " + filename);
   reader = new BufferedReader(new FileReader(filename));
  } catch (IOException e) {
   throw new RuntimeException(e);
  }
 }
}

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

static public void main (String[] args) throws Exception {
    Settings settings = null;
    String input = null, output = null, packFileName = "pack.atlas";

    switch (args.length) {
    case 4:
      settings = new Json().fromJson(Settings.class, new FileReader(args[3]));
    case 3:
      packFileName = args[2];
    case 2:
      output = args[1];
    case 1:
      input = args[0];
      break;
    default:
      System.out.println("Usage: inputDir [outputDir] [packFileName] [settingsFileName]");
      System.exit(0);
    }

    if (output == null) {
      File inputFile = new File(input);
      output = new File(inputFile.getParentFile(), inputFile.getName() + "-packed").getAbsolutePath();
    }
    if (settings == null) settings = new Settings();

    process(settings, input, output, packFileName);
  }
}

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

public void open(Map<String, Object> config, TopologyContext context,
         SpoutOutputCollector collector) {
  this.collector = collector;
  this.pending = new ConcurrentHashMap<UUID, Values>();
  try {
    this.br = new BufferedReader(new FileReader(new File(this
        .filePath)));
  } catch (Exception ex) {
    ex.printStackTrace();
  }
}

代码示例来源:origin: stackoverflow.com

LineNumberReader  lnr = new LineNumberReader(new FileReader(new File("File1")));
lnr.skip(Long.MAX_VALUE);
System.out.println(lnr.getLineNumber() + 1); //Add 1 because line index starts at 0
// Finally, the LineNumberReader object should be closed to prevent resource leak
lnr.close();

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

private static String readFromOsRelease() throws Exception {
  try (FileReader fileReader = new FileReader(new File("/etc/os-release"))) {
    Properties properties = new Properties();
    properties.load(fileReader);
    return unQuote(properties.getProperty("PRETTY_NAME"));
  }
}

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

public static void main(String[] args) throws IOException {
 if (args.length < 3) {
  log.info("usage: XMLBeginEndIterator file element keepInternalBoolean");
  return;
 }
 Reader in = new FileReader(args[0]);
 Iterator<String> iter = new XMLBeginEndIterator<>(in, args[1], args[2].equalsIgnoreCase("true"));
 while (iter.hasNext()) {
  String s = iter.next();
  System.out.println("*************************************************");
  System.out.println(s);
 }
 in.close();
}

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

private void readRawBytes(String fileName) throws IOException {
 BufferedReader in = new BufferedReader(new FileReader(fileName));
 StringBuffer buf = new StringBuffer();
 int c;
 while ((c = in.read()) >= 0)
  buf.append((char) c);
 mRawBuffer = buf.toString();
 // System.out.println(mRawBuffer);
 in.close();
}

代码示例来源:origin: stackoverflow.com

BufferedReader br = new BufferedReader(new FileReader("file.txt"));
try {
  StringBuilder sb = new StringBuilder();
  String line = br.readLine();

  while (line != null) {
    sb.append(line);
    sb.append(System.lineSeparator());
    line = br.readLine();
  }
  String everything = sb.toString();
} finally {
  br.close();
}

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

public static void main(String[] args) throws Exception {
 BufferedReader br = new BufferedReader(new FileReader("/tmp/acstats"));
 Prior p = new Prior(br);
 HashSet<String> hs = new HashSet<String>();
 hs.add("workshopname");
 //hs.add("workshopacronym");
 double d = p.get(hs);
 System.out.println("d is " + d);
}

代码示例来源:origin: stackoverflow.com

try (BufferedReader br = new BufferedReader(new FileReader(file))) {
  String line;
  while ((line = br.readLine()) != null) {
    // process the line.
  }
}

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

static public void main (String[] args) throws Exception {
    Settings settings = null;
    String input = null, output = null, packFileName = "pack.atlas";

    switch (args.length) {
    case 4:
      settings = new Json().fromJson(Settings.class, new FileReader(args[3]));
    case 3:
      packFileName = args[2];
    case 2:
      output = args[1];
    case 1:
      input = args[0];
      break;
    default:
      System.out.println("Usage: inputDir [outputDir] [packFileName] [settingsFileName]");
      System.exit(0);
    }

    if (output == null) {
      File inputFile = new File(input);
      output = new File(inputFile.getParentFile(), inputFile.getName() + "-packed").getAbsolutePath();
    }
    if (settings == null) settings = new Settings();

    process(settings, input, output, packFileName);
  }
}

代码示例来源:origin: commons-io/commons-io

@Test
public void testFilteringBufferedReader() throws Exception {
  final String encoding = "UTF-8";
  final String fileName = "LineIterator-Filter-test.txt";
  final File testFile = new File(getTestDirectory(), fileName);
  final List<String> lines = createLinesFile(testFile, encoding, 9);
  final Reader reader = new BufferedReader(new FileReader(testFile));
  this.testFiltering(lines, reader);
}

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

@Override
public Router getRouter(URL url) {
  try {
    // Transform File URL into Script Route URL, and Load
    // file:///d:/path/to/route.js?router=script ==> script:///d:/path/to/route.js?type=js&rule=<file-content>
    String protocol = url.getParameter(Constants.ROUTER_KEY, ScriptRouterFactory.NAME); // Replace original protocol (maybe 'file') with 'script'
    String type = null; // Use file suffix to config script type, e.g., js, groovy ...
    String path = url.getPath();
    if (path != null) {
      int i = path.lastIndexOf('.');
      if (i > 0) {
        type = path.substring(i + 1);
      }
    }
    String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath())));
    // FIXME: this code looks useless
    boolean runtime = url.getParameter(Constants.RUNTIME_KEY, false);
    URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type)
        .addParameter(Constants.RUNTIME_KEY, runtime)
        .addParameterAndEncoded(Constants.RULE_KEY, rule);
    return routerFactory.getRouter(script);
  } catch (IOException e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

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

public static void main(String[] args) throws IOException {
 Reader in = new FileReader(args[0]);
 Tokenizer st = new NegraPennTokenizer(in);
 while (st.hasNext()) {
  String s = (String) st.next();
  System.out.println(s);
 }
}

代码示例来源: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: stackoverflow.com

BufferedReader br = new BufferedReader(new FileReader(path));
try {
  return br.readLine();
} finally {
  br.close();
}

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

private static void printLog( String description, File file, PrintStream out )
{
  if ( file != null && file.exists() )
  {
    out.println( String.format( "---------- BEGIN %s ----------", description ) );
    try ( BufferedReader reader = new BufferedReader( new FileReader( file ) ) )
    {
      reader.lines().forEach( out::println );
    }
    catch ( IOException ex )
    {
      out.println( "Unable to collect log files: " + ex.getMessage() );
      ex.printStackTrace( out );
    }
    finally
    {
      out.println( String.format( "---------- END %s ----------", description ) );
    }
  }
}

相关文章