java Examples-src-Main-Utilities-commonutilitiesclass.java
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Examples-src-Main-Utilities-commonutilitiesclass.java相关的知识,希望对你有一定的参考价值。
// For complete examples and data files, please go to https://github.com/groupdocs-comparison/GroupDocs.Comparison-for-Java
public class Utilities {
// ExStart:CommonProperties
public final static String sourcePath = "./Data/SourceFiles/";
public final static String targetPath = "./Data/TargetFiles/";
public static final Path resultFilePath = getProjectBaseDir().resolve("Data/ResultFiles/output");
public final static String resultFile = "result";
public static final Path licensePath = getProjectBaseDir().resolve("GroupDocs.Total.Java.lic");
public final static String sourcePassword = "pass";
public final static String targetPassword = "pass";
public static String outputFileName(String extension) {
String resultPath = resultFilePath + extension;
return resultPath;
}
// ExEnd:CommonProperties
/**
* This method applies product license from file
*
*/
public static void applyLicenseFromFile() {
//ExStart:applyLicenseFromFile
try {
// Setup license
License lic = new License();
lic.setLicense(licensePath.toString());
} catch (Exception exp) {
System.out.println("Exception: " + exp.getMessage());
exp.printStackTrace();
}
//ExEnd:applyLicenseFromFile
}
/*
* get project base directories
*/
public static Path getProjectBaseDir() {
Properties props = new Properties();
try {
InputStream i = Utilities.class.getResourceAsStream("/project.properties");
props.load(i);
} catch (IOException x) {
throw new RuntimeException(x);
}
return FileSystems.getDefault().getPath(props.getProperty("project.basedir"));
}
/**
* This method applies product license from stream
*
*/
public static void applyLicenseFromStream(String filePath) {
// ExStart:ApplyLicenseFromStreamObj
try {
// Obtain license stream
FileInputStream licenseStream = new FileInputStream(filePath);
// Setup license
License lic = new License();
lic.setLicense(licenseStream);
} catch (Exception exp) {
System.out.println("Exception: " + exp.getMessage());
exp.printStackTrace();
}
// ExEnd:ApplyLicenseFromStreamObj
}
public static InputStream sourceStream(String sourceFile) throws Throwable {
String sourceFilePath = sourcePath + sourceFile;
InputStream sourceStream = new FileInputStream(sourceFilePath);
return sourceStream;
}
public static InputStream targetStream(String targetFile) throws Throwable {
String targetFilePath = targetPath + targetFile;
InputStream targetStream = new FileInputStream(targetFilePath);
return targetStream;
}
}
以上是关于java Examples-src-Main-Utilities-commonutilitiesclass.java的主要内容,如果未能解决你的问题,请参考以下文章
Java 布尔运算
java [Java] Java常用代码#java
Java - 35 Java 实例
Java While 循环
Java 字符串
Java If ... Else