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

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

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

BufferedReader.<init>介绍

[英]Constructs a new BufferedReader, providing in with a buffer of 8192 characters.
[中]构造一个新的BufferedReader,为in提供8192个字符的缓冲区。

代码示例

canonical example by Tabnine

public void postRequest(String urlStr, String jsonBodyStr) throws IOException {
  URL url = new URL(urlStr);
  HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  httpURLConnection.setDoOutput(true);
  httpURLConnection.setRequestMethod("POST");
  httpURLConnection.setRequestProperty("Content-Type", "application/json");
  try (OutputStream outputStream = httpURLConnection.getOutputStream()) { 
   outputStream.write(jsonBodyStr.getBytes());
   outputStream.flush();
  }
  if (httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
    try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()))) {
      String line;
      while ((line = bufferedReader.readLine()) != null) {
        // ... do something with line
      }
    }
  } else {
    // ... do something with unsuccessful response
  }
}

canonical example by Tabnine

public void readAllLines(InputStream in) throws IOException {
 try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in))) {
  String line;
  while ((line = bufferedReader.readLine()) != null) {
   // ... do something with line
  }
 }
}

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

String contentType = connection.getHeaderField("Content-Type");
String charset = null;

for (String param : contentType.replace(" ", "").split(";")) {
  if (param.startsWith("charset=")) {
    charset = param.split("=", 2)[1];
    break;
  }
}

if (charset != null) {
  try (BufferedReader reader = new BufferedReader(new InputStreamReader(response, charset))) {
    for (String line; (line = reader.readLine()) != null;) {
      // ... System.out.println(line) ?
    }
  }
} else {
  // It's likely binary content, use InputStream/OutputStream.
}

代码示例来源:origin: eugenp/tutorials

private String bodyToString(InputStream body) throws IOException {
    StringBuilder builder = new StringBuilder();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(body, StandardCharsets.UTF_8));
    String line = bufferedReader.readLine();
    while (line != null) {
      builder.append(line).append(System.lineSeparator());
      line = bufferedReader.readLine();
    }
    bufferedReader.close();
    return builder.toString();
  }
}

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

String result = new BufferedReader(new InputStreamReader(inputStream))
.lines().collect(Collectors.joining("\n"));

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

void method() throws Exception {
  final String fileName = "Test";
  final BufferedReader br = new BufferedReader(new InputStreamReader(
      new FileInputStream(fileName), StandardCharsets.UTF_8));
  try {
  } finally {
    br.close();
  }
}

代码示例来源:origin: google/guava

private static List<String> readUsingJava(String input, int chunk) throws IOException {
 BufferedReader r = new BufferedReader(getChunkedReader(input, chunk));
 List<String> lines = Lists.newArrayList();
 String line;
 while ((line = r.readLine()) != null) {
  lines.add(line);
 }
 r.close();
 return lines;
}

代码示例来源: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: apache/incubator-dubbo

/**
 * read lines.
 *
 * @param is input stream.
 * @return lines.
 * @throws IOException
 */
public static String[] readLines(InputStream is) throws IOException {
  List<String> lines = new ArrayList<String>();
  BufferedReader reader = new BufferedReader(new InputStreamReader(is));
  try {
    String line;
    while ((line = reader.readLine()) != null) {
      lines.add(line);
    }
    return lines.toArray(new String[0]);
  } finally {
    reader.close();
  }
}

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

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

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

String newLine = System.getProperty("line.separator");
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder result = new StringBuilder();
String line; boolean flag = false;
while ((line = reader.readLine()) != null) {
  result.append(flag? newLine: "").append(line);
  flag = true;
}
return result.toString();

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

private static String getValue(Part part) throws IOException {
  BufferedReader reader = new BufferedReader(new InputStreamReader(part.getInputStream(), "UTF-8"));
  StringBuilder value = new StringBuilder();
  char[] buffer = new char[1024];
  for (int length = 0; (length = reader.read(buffer)) > 0;) {
    value.append(buffer, 0, length);
  }
  return value.toString();
}

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

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

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

/**
 * For testing only.
 */
public static void main(String[] args) throws IOException {
 Tokenizer<String> t = new LexerTokenizer(new JFlexDummyLexer((Reader) null), new BufferedReader(new FileReader(args[0])));
 while (t.hasNext()) {
  System.out.println("token " + t.next());
 }
}

代码示例来源: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: 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);
}

相关文章