本文整理汇总了Java中org.apache.commons.io.FileUtils.getFile方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.getFile方法的具体用法?Java FileUtils.getFile怎么用?Java FileUtils.getFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.FileUtils
的用法示例。
在下文中一共展示了FileUtils.getFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void main() throws IOException {
File a = FileUtils.getFile("D:/a.txt");
String str = FileUtils.readFileToString(a,"utf-8");
JSONObject json = JSON.parseObject(str);
JSONArray arry = JSONArray.parseArray(json.get("delegates").toString());
for(int i = 0;i<arry.size();i++){
JSONObject obj= (JSONObject) arry.get(i);
String username = obj.getString("username");
String productivity = obj.getString("productivity");
String producedblocks = obj.getString("producedblocks");
String balance = obj.getString("balance");
String approval = obj.getString("approval");
System.out.println(username +"||" + productivity +"||" + producedblocks + "||" + balance + "||" + approval);
}
}
示例2: securityOperation
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void securityOperation(String filePath, boolean cover, SecurityOperation operation) throws Exception {
File file = FileUtils.getFile(filePath);
Collection<File> files;
if (file.exists()) {
if (file.isDirectory()) {
files = FileUtils.listFiles(file, LEGAL_EXTENSION, true);
} else if (file.isFile()) {
files = Collections.singletonList(file);
} else {
System.err.println("Invalid file or directory");
return;
}
} else {
System.err.println("Current os is " + SystemUtils.OS_NAME + " and " + filePath + " not exists");
return;
}
for (File f : files) {
String fileContent = FileUtils.readFileToString(f, StandardCharsets.UTF_8);
final boolean isBase64 = Base64.isBase64(fileContent);
// 防止一个文件多次被编码
if (isBase64 && operation == SecurityOperation.ENCODE) {
System.out.println(f.getName() + "是Base64编码,忽略加密操作...");
} else if (!isBase64 && operation == SecurityOperation.DECODE) {
System.out.println(f.getName() + "是明文文件,忽略解密操作...");
} else {
String transformString;
switch (operation) {
case DECODE:
transformString = decode(fileContent);
break;
case ENCODE:
transformString = encode(fileContent);
break;
default:
System.err.println("not have this security operation");
return;
}
if (cover) {
FileUtils.writeStringToFile(f, transformString, StandardCharsets.UTF_8);
System.out.println(f.getPath() + " 操作完成");
} else {
String bakFilePath = f.getAbsolutePath() + ".bak";
File bakFile = FileUtils.getFile(bakFilePath);
FileUtils.writeStringToFile(bakFile, transformString, StandardCharsets.UTF_8);
System.out.println("创建" + bakFile.getPath() + " 操作完成");
}
}
}
}