org.apache.commons.io.FileUtils.lineIterator()方法的使用及代码示例

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

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

FileUtils.lineIterator介绍

[英]Returns an Iterator for the lines in a File using the default encoding for the VM.
[中]使用VM的默认编码为File中的行返回迭代器。

代码示例

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

/**
 * Returns an Iterator for the lines in a <code>File</code> using the default encoding for the VM.
 *
 * @param file the file to open for input, must not be {@code null}
 * @return an Iterator of the lines in the file, never {@code null}
 * @throws IOException in case of an I/O error (file closed)
 * @see #lineIterator(File, String)
 * @since 1.3
 */
public static LineIterator lineIterator(final File file) throws IOException {
  return lineIterator(file, null);
}

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

/**
 * Return an Iterator for the lines in a <code>File</code> using the default encoding for the VM.
 *
 * @param file  the file to open for input, must not be <code>null</code>
 * @return an Iterator of the lines in the file, never <code>null</code>
 * @throws IOException in case of an I/O error (file closed)
 * @since Commons IO 1.3
 * @see #lineIterator(File, String)
 */
public static LineIterator lineIterator(File file) throws IOException {
  return lineIterator(file, null);
}

代码示例来源:origin: deeplearning4j/nd4j

INDArray newArr = Nd4j.zeros(2, 2);
try {
  LineIterator it = FileUtils.lineIterator(jsonFile);
  try {
    while (it.hasNext()) {

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

@Test
public void testNextLineOnlyNullEncoding() throws Exception {
  final String encoding = null;
  final File testFile = new File(getTestDirectory(), "LineIterator-nextOnly.txt");
  final List<String> lines = createLinesFile(testFile, encoding, 3);
  final LineIterator iterator = FileUtils.lineIterator(testFile, encoding);
  assertLines(lines, iterator);
}

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

@Test
public void testNextLineOnlyDefaultEncoding() throws Exception {
  final File testFile = new File(getTestDirectory(), "LineIterator-nextOnly.txt");
  final List<String> lines = createLinesFile(testFile, 3);
  final LineIterator iterator = FileUtils.lineIterator(testFile);
  assertLines(lines, iterator);
}

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

@Test
public void testNextLineOnlyUtf8Encoding() throws Exception {
  final String encoding = "UTF-8";
  final File testFile = new File(getTestDirectory(), "LineIterator-nextOnly.txt");
  final List<String> lines = createLinesFile(testFile, encoding, 3);
  final LineIterator iterator = FileUtils.lineIterator(testFile, encoding);
  assertLines(lines, iterator);
}

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

@Test
public void testMissingFile() throws Exception {
  final File testFile = new File(getTestDirectory(), "dummy-missing-file.txt");
  LineIterator iterator = null;
  try {
    iterator = FileUtils.lineIterator(testFile, "UTF-8");
    fail("Expected FileNotFoundException");
  } catch (final FileNotFoundException expected) {
    // ignore, expected result
  } finally {
    LineIterator.closeQuietly(iterator);
  }
}

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

@Test
public void testInvalidEncoding() throws Exception {
  final String encoding = "XXXXXXXX";
  final File testFile = new File(getTestDirectory(), "LineIterator-invalidEncoding.txt");
  createLinesFile(testFile, "UTF-8", 3);
  LineIterator iterator = null;
  try {
    iterator = FileUtils.lineIterator(testFile, encoding);
    fail("Expected UnsupportedCharsetException");
  } catch (final UnsupportedCharsetException expected) {
    // ignore, expected result
  } finally {
    LineIterator.closeQuietly(iterator);
  }
}

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

@Test
public void testNextOnly() throws Exception {
  final String encoding = null;
  final File testFile = new File(getTestDirectory(), "LineIterator-nextOnly.txt");
  final List<String> lines = createLinesFile(testFile, encoding, 3);
  final LineIterator iterator = FileUtils.lineIterator(testFile, encoding);
  try {
    for (int i = 0; i < lines.size(); i++) {
      final String line = iterator.next();
      assertEquals("next() line " + i, lines.get(i), line);
    }
    assertEquals("No more expected", false, iterator.hasNext());
  } finally {
    LineIterator.closeQuietly(iterator);
  }
}

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

@Test
public void testValidEncoding() throws Exception {
  final String encoding = "UTF-8";
  final File testFile = new File(getTestDirectory(), "LineIterator-validEncoding.txt");
  createLinesFile(testFile, encoding, 3);
  final LineIterator iterator = FileUtils.lineIterator(testFile, encoding);
  try {
    int count = 0;
    while (iterator.hasNext()) {
      assertNotNull(iterator.next());
      count++;
    }
    assertEquals(3, count);
  } finally {
    LineIterator.closeQuietly(iterator);
  }
}

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

final List<String> lines = createLinesFile(testFile, encoding, lineCount);
final LineIterator iterator = FileUtils.lineIterator(testFile, encoding);
try {
  try {

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

createLinesFile(testFile, encoding, 3);
final LineIterator iterator = FileUtils.lineIterator(testFile, encoding);
try {

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.io

/**
 * Returns an Iterator for the lines in a <code>File</code> using the default encoding for the VM.
 *
 * @param file  the file to open for input, must not be <code>null</code>
 * @return an Iterator of the lines in the file, never <code>null</code>
 * @throws IOException in case of an I/O error (file closed)
 * @since Commons IO 1.3
 * @see #lineIterator(File, String)
 */
public static LineIterator lineIterator(File file) throws IOException {
  return lineIterator(file, null);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-io

/**
 * Returns an Iterator for the lines in a <code>File</code> using the default encoding for the VM.
 *
 * @param file  the file to open for input, must not be <code>null</code>
 * @return an Iterator of the lines in the file, never <code>null</code>
 * @throws IOException in case of an I/O error (file closed)
 * @since Commons IO 1.3
 * @see #lineIterator(File, String)
 */
public static LineIterator lineIterator(File file) throws IOException {
  return lineIterator(file, null);
}

代码示例来源:origin: io.github.stephenc.docker/docker-client-shaded

/**
 * Returns an Iterator for the lines in a <code>File</code> using the default encoding for the VM.
 *
 * @param file the file to open for input, must not be {@code null}
 * @return an Iterator of the lines in the file, never {@code null}
 * @throws IOException in case of an I/O error (file closed)
 * @see #lineIterator(File, String)
 * @since 1.3
 */
public static LineIterator lineIterator(final File file) throws IOException {
  return lineIterator(file, null);
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

public FileLineDifferenceIterator(File marked, File available,
  @Nullable Function<String, String> transformer) throws IOException {
  this(FileUtils.lineIterator(marked, UTF_8.toString()),
    FileUtils.lineIterator(available, UTF_8.toString()), transformer);
}

代码示例来源:origin: org.apache.jackrabbit/oak-commons

public FileLineDifferenceIterator(File marked, File available,
  @Nullable Function<String, String> transformer) throws IOException {
  this(FileUtils.lineIterator(marked, UTF_8.toString()),
    FileUtils.lineIterator(available, UTF_8.toString()), transformer);
}

代码示例来源:origin: broadgsa/gatk

/**
 * Returns a file throwing a UserException if the file cannot be read.
 * @param file File
 * @return LineIterator
 */
public static LineIterator lineIterator(File file) {
  try {
    return FileUtils.lineIterator(file);
  } catch (IOException e) {
    throw new UserException.CouldNotReadInputFile(file, e);
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-tac-sfv-ir

@Override
public void processAll() throws Exception {
  File listFile = new File(fileListPath);
  File dataFolder = new File(listFile.getParent(),"data");
  LineIterator iterator = FileUtils.lineIterator(listFile);
  while(iterator.hasNext()){
    File f = new File(dataFolder,iterator.nextLine()+".sgm");
    String text = FileUtils.readFileToString(f);
    processDoc(text);
  }
  iterator.close();
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void fileIteratorBurnTest() throws Exception {
  Set<String> added = newHashSet("a", "z", "e", "b");
  File f = assertWrite(added.iterator(), false, added.size());
  BurnOnCloseFileIterator iterator =
    BurnOnCloseFileIterator.wrap(FileUtils.lineIterator(f, UTF_8.toString()), f);
  assertEquals(added, Sets.newHashSet(iterator));
  assertTrue(!f.exists());
}

相关文章

FileUtils类方法