apache-commons-io

How to find disk space of remote linux machine using Java [duplicate]

不问归期 提交于 2019-12-11 11:27:22
问题 This question already has answers here : How to find how much disk space is left using Java? (6 answers) Closed 5 years ago . I am looking for simple solution for finding total disk space and available space of a remove machine using java program. Please help Update There are questions already similar to this with primarily focus on local machine. I was looking solution for remote machine. 回答1: The easiest way to get the remote machine information and also safe way to do is to SSH to the

My Gradle project depends on commons-io 2.4, but Gradle puts $GRADLE_HOME/commons-io-1.4.jar into the classpath, causing failures

妖精的绣舞 提交于 2019-12-11 10:53:39
问题 I've been iterating on features in my first Gradle plugin. I determined early on that I needed commons-io, so I added a dependency on commons-io 2.4, being the latest version. This has been going well for a while, with the build working from the command line, and no errors in Eclipse. I just started trying to integrate some code that uses "FileUtils.write(File,String)". I didn't need that method before. I got everything un-redded in Eclipse, and then I tried a command line build. This failed

Why can't I read from /proc in Java using Commons IO FileUtils, but can do so using a plain FileInputStream?

三世轮回 提交于 2019-12-11 07:39:47
问题 I had a problem with reading /proc/%d/stat files using my Java method copyFiles() (source code below). I have found workaround using similar readProc() method. Now I am wondering what was the problem. Output files were created, but each file had 0 bytes (in /proc/ all files are 0 bytes because it is not standard filesystem). FileUtils is from the Apache Commons IO library. I've tried to do the same using java.nio - again, IOException is being thrown that attributes are wrong for each file. I

in java apache.commons.io,how to avoid to read the old log messages

拈花ヽ惹草 提交于 2019-12-11 01:43:40
问题 i am using the java Tail-listener API to do the tailf function(in Linux).ie,whenever log messages are updated in log file, this API will print the messages. My code is given below. public static void main(String[] args) { // TODO code application logic here File pcounter_log = new File("\vat\temp\test.log"); try { TailerListener listener = new PCTailListener(); Tailer tailer = new Tailer(pcounter_log, listener, 5000, true); Thread thread = new Thread(tailer); thread.start(); } catch

Progress bar with Apache FileUtils.copyDirectory(…)

こ雲淡風輕ζ 提交于 2019-12-10 15:53:50
问题 Does anyone know any way of implementing progress bar for Apache's FileUtils.copyDirectory(File src, File dst) ? I don't see anything helpful in JavaDocs and API. Seems like a common use case in dealing with batch disk operations, so I'm not sure if I miss something obvious. 回答1: I guess you will have to do that yourself. I see this immediate solution: Find all files you are about to copy and count the number or total file size first (depending on what your progress bar should measure) Copy

Java: list files recursively in subdirectories with Apache commons-IO 2.4

こ雲淡風輕ζ 提交于 2019-12-06 03:04:38
问题 I'm trying to list files with the extension ".xls" in the root directory and its sub-directories, using the following code with Apache Commons-IO 2.4 library. I am checking the size of the collection<File> , but it gives 0. I don't see where could be wrong in the code. Could you please help me with this? public static void main(String[] args) throws IOException { File rootDir = new File(args[0]); Collection<File> files = FileUtils.listFiles(rootDir, new RegexFileFilter("[a-zA-Z].xls"),

Images are not appearing good when converted from .docx to pdf

Deadly 提交于 2019-12-06 01:33:06
I converted .docx file to .pdf file, the text is converting fine, but the images in the .docx file is not appearing, instead it is represented as some special characters, below is my code: import com.lowagie.text.Document; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter; import java.io.File; import java.io.FileOutputStream; public class PDFConversion { /** * 14. This method is used to convert the given file to a PDF format 15. * * @param inputFile * - Name and the path of the file 16. * @param outputFile * - Name and the path where the PDF file to be saved 17. * @param

Java: list files recursively in subdirectories with Apache commons-IO 2.4

社会主义新天地 提交于 2019-12-04 08:27:25
I'm trying to list files with the extension ".xls" in the root directory and its sub-directories, using the following code with Apache Commons-IO 2.4 library. I am checking the size of the collection<File> , but it gives 0. I don't see where could be wrong in the code. Could you please help me with this? public static void main(String[] args) throws IOException { File rootDir = new File(args[0]); Collection<File> files = FileUtils.listFiles(rootDir, new RegexFileFilter("[a-zA-Z].xls"), DirectoryFileFilter.DIRECTORY); System.out.println("collection size:" + files.size()); } I found this works:

Delete all files in directory (but not directory) - one liner solution

假如想象 提交于 2019-12-03 18:18:25
问题 I want to delete all files inside ABC directory. When I tried with FileUtils.deleteDirectory(new File("C:/test/ABC/")); it also deletes folder ABC. Is there a one liner solution where I can delete files inside directory but not directory? 回答1: FileUtils.cleanDirectory(directory); There is this method available in the same file. This will also recursively deletes all sub-folders and files under them. Docs: org.apache.commons.io.FileUtils.cleanDirectory 回答2: Do you mean like? for(File file: dir

in java TailListener,how to avoid duplicate log messages

*爱你&永不变心* 提交于 2019-12-02 02:15:45
问题 my code is given below . public static void main(String[] args) { // TODO code application logic here File pcounter_log = new File("c:\development\temp\test.log"); try { TailerListener listener = new PCTailListener(); Tailer tailer = new Tailer(pcounter_log, listener, 5000,true); Thread thread = new Thread(tailer); thread.start(); } catch (Exception e) { System.out.println(e); } } public class PCTailListener extends TailerListenerAdapter { public void handle(String line) { System.out.println