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

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

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

FileReader.read介绍

暂无

代码示例

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

public void ioOperation5() {
  File file = new File("temp.txt");
  try (FileReader fr = new FileReader(file)) {
    char[] buffer = new char[BUFFER_LENGTH];
    fr.read(buffer, BUFFER_LENGTH, 1);
  } catch (Exception e) {
  }
}

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

public void ioOperation3() {
  File file = new File("temp.txt");
  try (FileReader fr = new FileReader(file)) {
    char[] buffer = new char[BUFFER_LENGTH];
    fr.read(buffer, 1, BUFFER_LENGTH);
  } catch (Exception e) {
  }
}

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

public void ioOperation4() {
  File file = new File("temp.txt");
  try (FileReader fr = new FileReader(file)) {
    char[] buffer = new char[BUFFER_LENGTH];
    fr.read(buffer, 2, BUFFER_LENGTH);
  } catch (Exception e) {
  }
}

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

public void ioOperation2() {
  File file = new File("temp.txt");
  try (FileReader fr = new FileReader(file)) {
    char[] buffer = new char[BUFFER_LENGTH];
    fr.read(buffer, BUFFER_LENGTH + 2, 1);
  } catch (Exception e) {
  }
}

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

public void ioOperation3() {
  File file = new File("temp.txt");
  try (FileReader fr = new FileReader(file)) {
    char[] buffer = new char[BUFFER_LENGTH];
    fr.read(buffer, BUFFER_LENGTH, 0);
  } catch (Exception e) {
  }
}

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

public void ioOperation2() {
  File file = new File("temp.txt");
  try (FileReader fr = new FileReader(file)) {
    char[] buffer = new char[BUFFER_LENGTH];
    fr.read(buffer, 0, BUFFER_LENGTH + 2);
  } catch (Exception e) {
  }
}

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

public void ioOperation2() {
  File file = new File("temp.txt");
  try (FileReader fr = new FileReader(file)) {
    char[] buffer = new char[BUFFER_LENGTH];
    fr.read(buffer, 0, BUFFER_LENGTH);
  } catch (Exception e) {
  }
}

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

public void ioOperation1() {
  File file = new File("temp.txt");
  try (FileReader fr = new FileReader(file)) {
    char[] buffer = new char[BUFFER_LENGTH];
    fr.read(buffer, BUFFER_LENGTH + 1, 1);
  } catch (Exception e) {
  }
}

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

private static String fileToString(File f) throws Exception {
  StringWriter output = new StringWriter();
  FileReader input = new FileReader(f);
  char[] buffer = new char[8 * 1024];
  int n = 0;
  while (-1 != (n = input.read(buffer))) {
    output.write(buffer, 0, n);
  }
  return output.toString();
}

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

public void ioOperation1() {
  File file = new File("temp.txt");
  try (FileReader fr = new FileReader(file)) {
    char[] buffer = new char[BUFFER_LENGTH];
    fr.read(buffer, 0, BUFFER_LENGTH + 1);
  } catch (Exception e) {
  }
}

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

public void ioOperation1() {
  File file = new File("temp.txt");
  try (FileReader fr = new FileReader(file)) {
    char[] buffer = new char[BUFFER_LENGTH];
    fr.read(buffer, 0, 1);
  } catch (Exception e) {
  }
}

代码示例来源: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: 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: h2oai/h2o-2

public static String readFile(File file) {
 FileReader r = null;
 try {
  r = new FileReader(file);
  char[] data = new char[(int) file.length()];
  r.read(data);
  return new String(data);
 } catch(IOException e) {
  throw Log.errRTExcept(e);
 } finally {
  close(r);
 }
}

代码示例来源:origin: alipay/sofa-rpc

/**
 * 读取文件内容
 *
 * @param file 文件
 * @return 文件内容
 * @throws IOException 发送IO异常
 */
public static String file2String(File file) throws IOException {
  if (file == null || !file.exists() || !file.isFile() || !file.canRead()) {
    return null;
  }
  FileReader reader = null;
  StringWriter writer = null;
  try {
    reader = new FileReader(file);
    writer = new StringWriter();
    char[] cbuf = new char[1024];
    int len = 0;
    while ((len = reader.read(cbuf)) != -1) {
      writer.write(cbuf, 0, len);
    }
    return writer.toString();
  } finally {
    IOUtils.closeQuietly(reader);
    IOUtils.closeQuietly(writer);
  }
}

代码示例来源:origin: alipay/sofa-rpc

/**
 * 读取文件内容
 *
 * @param file 文件
 * @return 文件内容
 * @throws IOException 发送IO异常
 */
public static String file2String(File file) throws IOException {
  if (file == null || !file.exists() || !file.isFile() || !file.canRead()) {
    return null;
  }
  FileReader reader = null;
  StringWriter writer = null;
  try {
    reader = new FileReader(file);
    writer = new StringWriter();
    char[] cbuf = new char[1024];
    int len = 0;
    while ((len = reader.read(cbuf)) != -1) {
      writer.write(cbuf, 0, len);
    }
    return writer.toString();
  } finally {
    IOUtils.closeQuietly(reader);
    IOUtils.closeQuietly(writer);
  }
}

代码示例来源:origin: sonyxperiadev/ApkAnalyser

FileReader reader = new FileReader(f2);
while (reader.read(buf) != -1 && buf.length() < 4);
if (buf.length() == 4 && buf.toString().equals("test")) {
  return false;

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

int len = reader.read(buffer);
buffer.flip();

代码示例来源:origin: groovy/groovy-core

private void ensureResultOK(final String classname) {
  if (!(new File(classDirectory + classname + ".class")).exists()) {
    fail("Class file for " + classname + " does not exist and should.");
  }
  final File result = new File(classDirectory + classname + "_Result.txt");
  final char[] buffer = new char[10];
  try {
    (new FileReader(result)).read(buffer);
    assertEquals("OK.", new String(buffer).trim());
  } catch (final FileNotFoundException fnfe) {
    fail("File " + result.getName() + " should have been created but wasn't.");
  } catch (final IOException ioe) {
    fail("Error reading file " + result.getName() + ".");
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

private static void runPerfTests(final String[] args, final List<Setup> tests) throws IOException,
    InterruptedException, FileNotFoundException {
  final String java = args.length > 0 ? args[0] : "java";
  final int repeat = args.length > 1 ? Integer.parseInt(args[1]) : 5;
  int x = 0;
  for (final Setup setup : tests) {
    System.out.print(setup.description());
    final ProcessBuilder pb = setup.throughputTest(java);
    pb.redirectErrorStream(true); // merge System.out and System.err
    final long t1 = System.nanoTime();
    final int count = setup.threadCount >= 4 ? 3 : repeat;
    runPerfTest(count, x++, setup, pb);
    System.out.printf(" took %.1f seconds%n", (System.nanoTime() - t1) / (1000.0 * 1000.0 * 1000.0));
    final FileReader reader = new FileReader(setup.temp);
    final CharBuffer buffer = CharBuffer.allocate(256 * 1024);
    reader.read(buffer);
    reader.close();
    setup.temp.delete();
    buffer.flip();
    final String raw = buffer.toString();
    System.out.print(raw);
    final Stats stats = new Stats(raw);
    System.out.println(stats);
    System.out.println("-----");
    setup.stats = stats;
  }
  new File("perftest.log").delete();
}

相关文章