本文整理了Java中org.apache.uima.util.FileUtils
类的一些代码示例,展示了FileUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils
类的具体详情如下:
包路径:org.apache.uima.util.FileUtils
类名称:FileUtils
[英]Some utilities for handling files.
[中]一些用于处理文件的实用程序。
代码示例来源:origin: org.apache.uima/uimaj-tools
/**
* Read stylemap file.
*
* @param smapFile the smap file
* @return the string
*/
protected String readStylemapFile(File smapFile) // JMP
{
String styleMapXml = "";
if (smapFile.exists()) {
try {
return FileUtils.file2String(smapFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return styleMapXml;
}
代码示例来源:origin: apache/uima-uimaj
/**
* Recursively delete possibly non-empty directory or file.
*
* @param file
* The file or directory to be deleted.
* @return <code>true</code> iff the file/directory could be deleted.
*/
public static final boolean deleteRecursive(File file) {
if (!file.exists()) {
return false;
}
boolean rc = true;
if (file.isDirectory()) {
File[] fileList = file.listFiles();
for (int i = 0; i < fileList.length; i++) {
rc &= deleteRecursive(fileList[i]);
}
}
rc &= file.delete();
return rc;
}
代码示例来源:origin: ClearTK/cleartk
public static File getCleanedTimeBankDir(String timeBankDir) throws IOException {
File tempDir = File.createTempFile("TimeBank", "Cleaned");
tempDir.delete();
tempDir.mkdir();
for (File file : new File(timeBankDir).listFiles()) {
String name = file.getName();
if (file.isHidden() || name.startsWith(".")) {
continue;
}
// get the file text
String text = FileUtils.file2String(file);
// all ampersands are messed up in TimeBank
text = text.replaceAll("\\bamp\\b", "&");
text = text.replaceAll("SampP", "S&P");
text = text.replaceAll("&&;", "&");
// all "---" missing in TreeBank
text = text.replaceAll("---", "");
// fix individual file errors
text = fixTextByFileName(name, text);
// write the file to the temp directory
FileUtils.saveString2File(text, new File(tempDir, file.getName()));
}
return tempDir;
}
代码示例来源:origin: apache/uima-uimaj
/**
* Read the contents of a file into a string using a specific character encoding.
*
* @param file
* The input file.
* @param fileEncoding
* The character encoding of the file (see your Java documentation for supported
* encodings).
* @return String The contents of the file.
* @throws IOException
* Various I/O errors.
*/
public static String file2String(File file, String fileEncoding) throws IOException {
if (fileEncoding == null) { // use default
return file2String(file);
}
return reader2String(new InputStreamReader(new FileInputStream(file), fileEncoding));
}
代码示例来源:origin: org.apache.uima/textmarker-core
private void writeStyleFile(String output, String styleMapLocation) throws IOException {
File file = new File(styleMapLocation);
FileUtils.saveString2File(output, file);
}
代码示例来源:origin: apache/uima-uimaj
/**
* Read the contents of a file into a string, using the default platform encoding.
*
* @param file
* The file to be read in.
* @return String The contents of the file.
* @throws IOException
* Various I/O errors.
*/
public static String file2String(File file) throws IOException {
return reader2String(new FileReader(file));
}
代码示例来源:origin: edu.utah.bmi.nlp/nlp-core
/**
* @param descriptor
* @param cpeDescSaveFile
*/
private void updateImport(CpeComponentDescriptor descriptor, File cpeDescSaveFile) throws Exception {
//don't touch import by name
if (descriptor.getImport() != null && descriptor.getImport().getName() != null)
return;
//for include or import by location, get the absolute URL of the descriptor
URL descUrl = descriptor.findAbsoluteUrl(defaultResourceManager);
//don't touch URLs with protocol other than file:
if ("file".equals(descUrl.getProtocol())) {
File descFile = urlToFile(descUrl);
//try to find relative path from cpeDescSaveFile to descFile
String relPath = FileUtils.findRelativePath(descFile, cpeDescSaveFile.getParentFile());
if (relPath != null) {
//update CPE descriptor
descriptor.setInclude(null);
Import newImport = UIMAFramework.getResourceSpecifierFactory().createImport();
newImport.setLocation(relPath);
descriptor.setImport(newImport);
}
}
}
代码示例来源:origin: org.apache.uima/ruta-core
private void writeStyleFile(String output, String styleMapLocation) throws IOException {
File file = new File(styleMapLocation);
FileUtils.saveString2File(output, file);
}
代码示例来源:origin: org.apache.uima/uimaj-v3migration-jcas
} else {
v2Source = FileUtils.reader2String(Files.newBufferedReader(p));
cc = sourceToCommonConverted.get(v2Source);
if (null == cc) {
代码示例来源:origin: org.apache.uima/uimaj-tools
/**
* Update import.
*
* @param descriptor the descriptor
* @param cpeDescSaveFile the cpe desc save file
* @throws Exception the exception
*/
private void updateImport(CpeComponentDescriptor descriptor, File cpeDescSaveFile) throws Exception {
//don't touch import by name
if (descriptor.getImport() != null && descriptor.getImport().getName() != null)
return;
//for include or import by location, get the absolute URL of the descriptor
URL descUrl = descriptor.findAbsoluteUrl(defaultResourceManager);
//don't touch URLs with protocol other than file:
if ("file".equals(descUrl.getProtocol())) {
File descFile = urlToFile(descUrl);
//try to find relative path from cpeDescSaveFile to descFile
String relPath = FileUtils.findRelativePath(descFile, cpeDescSaveFile.getParentFile());
if (relPath != null) {
//update CPE descriptor
descriptor.setInclude(null);
Import newImport = UIMAFramework.getResourceSpecifierFactory().createImport();
newImport.setLocation(relPath);
descriptor.setImport(newImport);
}
}
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-resources
/**
* Read an entire file into a string, ignoring any leading or trailing whitespace.
*
* @param file to load
* @return the content of the file as a string.
* @throws IOException on error reading or accessing the file.
*/
public static String readFile(File file) throws IOException {
String contents = FileUtils.file2String(file);
contents = contents.replaceAll("\r\n", "\n");
return StringUtils.strip(contents);
}
代码示例来源:origin: org.apache.uima/uimaj-tools
original = FileUtils.file2String(file);
FileUtils.saveString2File(contents, file);
filesModified++;
代码示例来源:origin: DigitalPebble/behemoth
public void close() throws IOException {
if (cas != null)
cas.release();
if (tae != null)
tae.destroy();
if (installDir != null) {
FileUtils.deleteRecursive(installDir);
}
}
代码示例来源:origin: apache/uima-uimaj
/**
* Write a string to a file, using platform encoding. If the file exists, it is overwritten.
*
* @param fileContents
* The file contents.
* @param file
* The file to save to.
* @throws IOException
* If for any reason the file can't be written.
*/
public static void saveString2File(String fileContents, File file) throws IOException {
saveString2File(fileContents, file, Charset.defaultCharset().name());
}
代码示例来源:origin: dstl/baleen
/**
* Read an entire file into a string, ignoring any leading or trailing whitespace.
*
* @param file to load
* @return the content of the file as a string.
* @throws IOException on error reading or accessing the file.
*/
public static String readFile(File file) throws IOException {
String contents = FileUtils.file2String(file);
contents = contents.replaceAll("\r\n", "\n");
return StringUtils.strip(contents);
}
代码示例来源:origin: apache/uima-uimaj
String fileContents = FileUtils.file2String(file);
if (result.numReplaced > 0) {
FileUtils.saveString2File(fileContents, file);
System.out.println("File modified, number of instances replaced: " + result.numReplaced);
代码示例来源:origin: dstl/baleen
@After
public void tearDown() throws IOException {
FileUtils.deleteRecursive(tempDirectory.toFile());
}
}
代码示例来源:origin: org.cleartk/cleartk-util
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
String id = new File(ViewUriUtil.getURI(jCas)).getName();
File outFile = new File(this.outputDirectory, id + ".txt");
try {
FileUtils.saveString2File(jCas.getDocumentText(), outFile);
} catch (IOException e) {
throw new AnalysisEngineProcessException(e);
}
}
代码示例来源:origin: org.apache.uima/uimaj-tools
/**
* Load file.
*
* @return true, if successful
*/
private boolean loadFile() {
if (!this.logFile.exists()) {
JOptionPane.showMessageDialog(this, "The log file \"" + this.logFile.getAbsolutePath()
+ "\" does not exist (yet).\nThis probably just means that nothing was logged yet.",
"Information", JOptionPane.INFORMATION_MESSAGE);
return false;
}
String text = null;
try {
text = FileUtils.file2String(this.logFile, "UTF-8");
} catch (IOException e) {
handleException(e);
return false;
}
this.textArea.setText(text);
return true;
}
代码示例来源:origin: org.apache.uima/uimaj-v3migration-jcas
FileUtils.deleteRecursive(new File(outputDirectory));
内容来源于网络,如有侵权,请联系作者删除!