apache-commons-io

in java TailListener,how to avoid duplicate log messages

最后都变了- 提交于 2019-12-01 21:32:00
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(line); } } .ie, i am monitoring the log file.whenever log messages updated in log file(c:\development

Make FileAlterationObserver to observe remote directory

一世执手 提交于 2019-12-01 14:37:24
How to make FileAlterationObserver to observe a remote directory? This can accept a String path or a Java File . Both the cases it will look for the directory in local context. I have a directory in remote server file system. It would be also helpful if anyone tell me how to create a new File object referring to the file in the remote directory. Example: File file = new File("remote directory path"); You cannot. The File object cannot refer to an SFTP file. There's no way to have the SFTP server notify you on changes in a remote file/directory (the protocol itself does not have a mechanism for

Make FileAlterationObserver to observe remote directory

纵然是瞬间 提交于 2019-12-01 12:57:50
问题 How to make FileAlterationObserver to observe a remote directory? This can accept a String path or a Java File . Both the cases it will look for the directory in local context. I have a directory in remote server file system. It would be also helpful if anyone tell me how to create a new File object referring to the file in the remote directory. Example: File file = new File("remote directory path"); 回答1: You cannot. The File object cannot refer to an SFTP file. There's no way to have the

How to debug NoSuchMethodError exception?

江枫思渺然 提交于 2019-12-01 04:11:20
问题 I am running the following code package test.commons; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; public class Try_FileUtilsWrite { public static void main(String[] args) throws IOException { System.out.println(FileUtils.class.getClassLoader()); FileUtils.write(new File("output.txt"), "Hello world"); } } and getting Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.io.FileUtils.write(Ljava/io/File;Ljava/lang/CharSequence;)V

Do I need to close the input stream manually after using IOUtils.toString(input) of commons-io?

笑着哭i 提交于 2019-11-30 17:03:06
Commons-IO has an IOUtils.toString(inputStream) method, which can read all content from an input stream: InputStream input = getInputStream(); String content = IOUtils.toString(input); My question is shall I close the input stream manually after using it? I thought IOUtils may close it since it has read all the content, but I can't find that in the source code. JB Nizet The javadoc says: Wherever possible, the methods in this class do not flush or close the stream. This is to avoid making non-portable assumptions about the streams' origin and further use. Thus the caller is still responsible

Recursively finding only directories with FileUtils.listFiles

核能气质少年 提交于 2019-11-30 11:11:13
I want to collect a list of all files under a directory, in particular including subdirectories. I like not doing things myself, so I'm using FileUtils.listFiles from Apache Commons IO. So I have something like: import java.io.File; import java.util.Collection; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.TrueFileFilter; public class TestListFiles { public static void main(String[] args) { Collection<File> found = FileUtils.listFiles(new File("foo"), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (File f : found) { System.out.println("Found file: " +

Do I need to close the input stream manually after using IOUtils.toString(input) of commons-io?

拟墨画扇 提交于 2019-11-30 00:16:34
问题 Commons-IO has an IOUtils.toString(inputStream) method, which can read all content from an input stream: InputStream input = getInputStream(); String content = IOUtils.toString(input); My question is shall I close the input stream manually after using it? I thought IOUtils may close it since it has read all the content, but I can't find that in the source code. 回答1: The javadoc says: Wherever possible, the methods in this class do not flush or close the stream. This is to avoid making non

Commons-Io Duplicate Entry Error Using Robospice and Android Studio

泄露秘密 提交于 2019-11-29 22:59:48
问题 I've been working on the following issue for several hours, but haven't come up with a way to solve my problem. I've tried the following fixes from Stack Overflow (Android Studio update to 1.0 corrupts MultiDex and Duplicate Zip Entry after Gradle Plugin v0.13.1) but neither one of them worked. I am getting the following error when trying to build my program: Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry: org/apache/commons

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

假如想象 提交于 2019-11-29 18:47:48
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? 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 Do you mean like? for(File file: dir.listFiles()) if (!file.isDirectory()) file.delete(); This will only delete files, not directories. ChrisB Peter

Recursively finding only directories with FileUtils.listFiles

佐手、 提交于 2019-11-29 16:44:03
问题 I want to collect a list of all files under a directory, in particular including subdirectories. I like not doing things myself, so I'm using FileUtils.listFiles from Apache Commons IO. So I have something like: import java.io.File; import java.util.Collection; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.TrueFileFilter; public class TestListFiles { public static void main(String[] args) { Collection<File> found = FileUtils.listFiles(new File("foo"),