当前位置: 首页>>代码示例>>Java>>正文


Java FileUtils.readLines方法代码示例

本文整理汇总了Java中org.apache.commons.io.FileUtils.readLines方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.readLines方法的具体用法?Java FileUtils.readLines怎么用?Java FileUtils.readLines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.io.FileUtils的用法示例。


在下文中一共展示了FileUtils.readLines方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: properties2Xml

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * Properties 转换 string.xml
 *
 * @param file      properties文件
 * @param xmlCn     中文string.xml
 * @param xmlEn     英文string.xml
 */
public static void properties2Xml(File file, File xmlCn, File xmlEn) {
    try (FileInputStream in = FileUtils.openInputStream(file)){
        List<String> lines = FileUtils.readLines(file);
        // PrintUtils.list(lines);
        // Properties 并不遵循文件原来的顺序,所以采取读行的方式处理
        List<String> xmlLinesCn = new ArrayList<>(lines.size());
        List<String> xmlLinesEn = new ArrayList<>(lines.size());
        addHeader(xmlLinesCn);
        addHeader(xmlLinesEn);
        for(String line : lines){
            xmlLinesCn.add(itemXmlCn(line));
            xmlLinesEn.add(itemXmlEn(line));
        }
        addFooter(xmlLinesCn);
        addFooter(xmlLinesEn);
        FileUtils.deleteQuietly(xmlCn);
        FileUtils.writeLines(xmlCn, "UTF-8", xmlLinesCn);
        FileUtils.writeLines(xmlEn, "UTF-8", xmlLinesEn);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:linchaolong,项目名称:ExcelParser,代码行数:30,代码来源:Properties2Xml.java

示例2: test01

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void test01() throws Exception {
    List<String> lines = FileUtils.readLines(new File("E:\\stock\\up.txt"));
    List<Stock> stocks = new ArrayList<>();
    for (String line : lines) {
        System.out.println(line);
        if (line.startsWith("股票")) {
            continue;
        }
        String[] split = line.split("\\t");
        String name = split[0];
        String up = split[3];
        String hangye = split[4].split("\\-")[0];
        stocks.add(new Stock(name, up, hangye));
    }

    FileUtils.writeLines(new File("e:/stock/up2.txt"), stocks);
    System.out.println(stocks);
}
 
开发者ID:jt120,项目名称:take,代码行数:20,代码来源:UpTest.java

示例3: test

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
    final String providedInstanceProperty = "-D" + ProvidedScriptTaskRunnerMatlab.PROVIDED_INSTANCE_KEY + "="
            + JavaOctaveScriptTaskRunnerMatlab.class.getName();
    final String inputFile = new ClassPathResource(MainTest.class.getSimpleName() + "_input.csv", MainTest.class)
            .getFile().getAbsolutePath();
    final String outputFile = new File(ContextProperties.TEMP_DIRECTORY,
            MainTest.class.getSimpleName() + "_output.csv").getAbsolutePath();
    Main.main(new String[] { providedInstanceProperty, "-i", inputFile, "-o", outputFile });
    final List<String> optimalFStrs = FileUtils.readLines(new File(outputFile), Charset.defaultCharset());
    final List<Decimal> optimalFs = new ArrayList<Decimal>();
    for (final String optimalFStr : optimalFStrs) {
        optimalFs.add(new Decimal(optimalFStr).round(3));
    }
    Assertions.assertThat(optimalFs).isEqualTo(Arrays.asList(new Decimal("0.052"), new Decimal("0.213")));
}
 
开发者ID:subes,项目名称:invesdwin-context-matlab,代码行数:17,代码来源:MainTest.java

示例4: PluralFilter

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void PluralFilter(String oriPath, String domain) {
    File dirfile = new File(oriPath + "3_pluralFilter");
    if (!dirfile.exists() && !dirfile.isDirectory()) {
        dirfile.mkdir();
    }
    String InputFilePath = oriPath + "2_UselessFilter\\";
    List<String> fileName = null;
    try {
        fileName = FileUtils.readLines(new File(oriPath + "otherFiles\\" + domain + "_topics.txt"), "utf-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
    for (String name : fileName) {
        System.out.println("Plural Filter\t" + name);
        Topic curtopic = TxtToObject.SaveTxtToObj(InputFilePath + name + ".txt");
        traveralAndChange.traversalAllAndChange(curtopic);
        TxtToObject.writeObjToTxt(curtopic, oriPath + "3_pluralFilter\\" + name + ".txt");
    }
    System.out.println("Done.");
}
 
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:21,代码来源:CPluralFilter.java

示例5: FacetHyponymyMerge

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void FacetHyponymyMerge(String oriPath, String domain) {
    String InputFilePath = oriPath + "7_facetHyponymyMerge\\";
    String OutputFilePath = oriPath + "8_AddType";
    List<String> fileName = new ArrayList<>();
    try {
        fileName = FileUtils.readLines(new File(oriPath + "otherFiles\\" + domain + "_topics.txt"), "utf-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
    File dirfile = new File(OutputFilePath);
    if (!dirfile.exists() && !dirfile.isDirectory())
        dirfile.mkdir();
    AllHyponymy allHyponymy = GetHyponymy.GetHyponymyFromExl(oriPath + "otherFiles\\" + domain + "上下位.xls");
    for (String name : fileName) {
        System.out.println("Add type\t" + name);
        Topic topic = TxtToObject.SaveTxtToObj(InputFilePath + name + ".txt");
        topic = AddType(topic, allHyponymy);
        topic = OperationToTopic.OptimizeTopic(topic);
        TxtToObject.writeObjToTxt(topic, OutputFilePath + "\\" + name + ".txt");
    }
    System.out.println("done.");
}
 
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:23,代码来源:HAddType.java

示例6: read

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static List<HyperParameterScopeItem> read(final String configFilePath) {
    final File file = new File(configFilePath);
    List<String> lines;
    try {
        lines = FileUtils.readLines(file, Charsets.UTF_8);
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
    final List<HyperParameterScopeItem> result = Lists.newArrayList();
    for (final String line : lines) {
        final String[] segments = StringUtils.split(line, ',');
        final List<String> values = Lists.newArrayList();
        for (int i = 1; i < segments.length; ++i) {
            values.add(segments[i]);
        }
        final HyperParameterScopeItem item = new HyperParameterScopeItem(segments[0], values);
        result.add(item);
    }
    return result;
}
 
开发者ID:chncwang,项目名称:laozhongyi,代码行数:21,代码来源:HyperParameterScopeConfigReader.java

示例7: FacetHyponymyMerge

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void FacetHyponymyMerge(String oriPath, String domain) {
    String InputFilePath = oriPath + "6_AddExpRes\\";
    String OutputFilePath = oriPath + "7_facetHyponymyMerge";
    List<String> fileName = new ArrayList<>();
    try {
        fileName = FileUtils.readLines(new File(oriPath + "otherFiles\\" + domain + "_topics.txt"), "utf-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
    File dirfile = new File(OutputFilePath);
    if (!dirfile.exists() && !dirfile.isDirectory())
        dirfile.mkdir();
    HashMap<String, Integer> hyponymyIntegerHashMap = GetFacetHyponymy(oriPath + "5_giveInstinctiveFacets\\", fileName);
    Topic hyponymy = PreprocessFacetHyponymy(hyponymyIntegerHashMap);
    for (String name : fileName) {
        System.out.println("Facet Hyponymy Merge\t" + name);
        Topic topic = TxtToObject.SaveTxtToObj(InputFilePath + name + ".txt");
        topic = FacetHyponymyRecognition(topic, hyponymy.getFacets());
        topic = OperationToTopic.OptimizeTopic(topic);
        TxtToObject.writeObjToTxt(topic, OutputFilePath + "\\" + name + ".txt");
    }
    System.out.println("done.");
}
 
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:24,代码来源:GFacetHyponymyMerge.java

示例8: testSTM

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void testSTM() throws Exception {
  // simulated=false;
  // Monitor.debug=true;
  // debug=true;
  prepareOBDTriplet(simulated, debug);
  obdTriplet.initOBD();
  File logRoot = new File("src/test/data");
  File logFile = null;
  if (!simulated) {
    // FIXME - allow testing with test-Configuration
    Config config = Config.getInstance(ConfigMode.Test);
    logFile = obdTriplet.logResponses(logRoot, "testLogs");
  }
  int frameLimit = 150;
  obdTriplet.pidMonitor(obdTriplet.getCANValues(), frameLimit);
  obdTriplet.close();
  Platform.runLater(() -> display.close());
  if (!simulated) {
    assertTrue(logFile.exists());
    List<String> logLines = FileUtils.readLines(logFile, "UTF-8");
    assertTrue(logLines.size() > frameLimit);
  }
}
 
开发者ID:BITPlan,项目名称:can4eve,代码行数:25,代码来源:TestELM327.java

示例9: SaveContantAllTopics

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void SaveContantAllTopics(String oriPath, String domain)
{
	File dirfile =new File(oriPath + "1_origin");    
	if  (!dirfile .exists()  && !dirfile .isDirectory())      
	{       
	    dirfile .mkdir();    
	} 
	String dirPath = oriPath + "1_origin\\";
	List<String> topics = null;
	try {
		topics = FileUtils.readLines(new File(oriPath + "otherFiles\\" + domain + "_topics.txt"), "utf-8");
		System.out.println("共有" + topics.size() + "个术语");

		topics.forEach(topic -> wiki(dirPath, topic));

		System.out.println("Done.");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:21,代码来源:ASaveContentAllTopics.java

示例10: csvAssert

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void csvAssert(File f1, File f2)   {
	
	assertTrue(f1.getAbsolutePath()+ " not exists",  f1.exists());
	assertTrue(f2.getAbsolutePath()+ " not exists" , f2.exists());

	Set<String> f1Lines;
	try {
		f1Lines = new HashSet<String>(FileUtils.readLines(f1));
		Set<String> ff1Lines = new HashSet<String>(f1Lines);
		Set<String> f2Lines = new HashSet<String>(FileUtils.readLines(f2));
		Set<String> ff2Lines = new HashSet<String>(f2Lines);
		f1Lines.removeAll(ff2Lines);
		f2Lines.removeAll(ff1Lines);
		assertTrue("\n " + f1.getAbsolutePath() + " diff: \n " + StringUtils.join(f1Lines, "\n") + "\n-----------------\n" + f2.getAbsolutePath() + " diff: \n " + StringUtils.join(f2Lines, "\n"), f2Lines.isEmpty() && f1Lines.isEmpty());
	} catch (IOException e) {
		LOGGER.error("asserting: " + f1.getAbsolutePath() + " with target "  + f2.getAbsolutePath() , e );
		throw new AssertionError("asserting: " + f1.getAbsolutePath() + " with target "  + f2.getAbsolutePath(), e);
	}
}
 
开发者ID:rockitconsulting,项目名称:test.rockitizer,代码行数:20,代码来源:CSVFileAssertion.java

示例11: readLines

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static List<String> readLines(String fileName) throws URISyntaxException, IOException {
	File file = new File(FileReader.class.getResource(fileName).toURI());
	return FileUtils.readLines(file, Charset.defaultCharset());
}
 
开发者ID:if0nz,项目名称:advent-of-code-2017,代码行数:5,代码来源:FileReader.java

示例12: csvAssert

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void csvAssert(File f1, File f2) throws IOException  {
	
	assertTrue(f1.exists());
	assertTrue(f2.exists());

	Set<String> f1Lines = new HashSet<String>(FileUtils.readLines(f1));
	Set<String> ff1Lines = new HashSet<String>(f1Lines);
	Set<String> f2Lines = new HashSet<String>(FileUtils.readLines(f2));
	Set<String> ff2Lines = new HashSet<String>(f2Lines);
	f1Lines.removeAll(ff2Lines);
	f2Lines.removeAll(ff1Lines);
	assertTrue(f2Lines.isEmpty() && f1Lines.isEmpty());
}
 
开发者ID:rockitconsulting,项目名称:test.rockitizer,代码行数:14,代码来源:CSVFileAssertionTest.java

示例13: modifyFieldValue

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * relace const string in dexFile
 *
 * @param dexFile
 * @param outDexFile
 * @param orgFieldValue
 * @param newFieldValue
 * @return
 */
public static boolean modifyFieldValue(File dexFile, File outDexFile, String orgFieldValue,
                                       String newFieldValue) throws IOException, RecognitionException {
    File smaliFolder = new File(outDexFile.getParentFile(), "smali");
    if (smaliFolder.exists()) {
        FileUtils.deleteDirectory(smaliFolder);
    }
    smaliFolder.mkdirs();
    boolean disassembled = SmaliUtils.disassembleDexFile(dexFile, smaliFolder);
    if (disassembled) {
        Collection<File> smaliFiles = FileUtils.listFiles(smaliFolder, new String[]{"smali"}, true);
        for (File smaliFile : smaliFiles) {
            List<String> lines = FileUtils.readLines(smaliFile);
            for (int index = 0; index < lines.size(); index++) {
                String line = lines.get(index);
                String newLine = StringUtils.replace(line, "\"" + orgFieldValue + "\"", "\"" + newFieldValue + "\"");
                lines.set(index, newLine);
            }
            FileUtils.writeLines(smaliFile, lines);
        }

        //转换为dex文件
        boolean assembled = SmaliUtils.assembleSmaliFile(smaliFolder, outDexFile);
        if (assembled) {
            FileUtils.deleteDirectory(smaliFolder);
            return true;
        }
    }
    return false;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:39,代码来源:PatchFieldTool.java

示例14: read

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@NotNull
public Configuration read() throws IOException, ConfigurationParsingException {
    Configuration configuration = new Configuration();
    List<String> lines = FileUtils.readLines(new File(path));
    int lineNumber = 0;

    for (String line : lines) {
        lineNumber++;

        if (line.contains("=")) {
            int index = line.indexOf("=");
            String propertyName = line.substring(0, index).trim();
            String propertyValue = line.substring(index + 1, line.length()).trim();

            try {
                Property property = Property.valueOf(propertyName);
                configuration.set(property, propertyValue);
            } catch (IllegalArgumentException e) {
                throw new ConfigurationParsingException("Unknown property: " + propertyName);
            }
        } else {
            throw new ConfigurationParsingException("Corrupt property at line " + lineNumber);
        }
    }

    return configuration;
}
 
开发者ID:andreyfomenkov,项目名称:green-cat,代码行数:28,代码来源:ConfigurationReader.java

示例15: obtainContentFromFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
String obtainContentFromFile(String fileName) throws IOException {
  if (fileName == null) {
    return "";
  }
  fileName = getClass().getResource("/" + fileName).getFile();
  File file = new File(fileName);
  List<String> lines = FileUtils.readLines(file, FILE_ENCODING);
  StringBuilder stringBuilder = new StringBuilder();
  for (String line : lines) {
    stringBuilder.append(line);
  }
  return stringBuilder.toString();
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:14,代码来源:MockWebServerTest.java


注:本文中的org.apache.commons.io.FileUtils.readLines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。