java.nio.file

JMeter - Static method get( java.lang.String ) not found in class'java.nio.file.Paths'

偶尔善良 提交于 2019-12-01 02:30:59
问题 I am trying to create a JMeter load test. I need the test to take a sample log file and change its name. The only way I could find to do this was to copy the file in a BeanShell Preprocessor but I am getting the following error: ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: evalSourced file: inline evaluation of: ``import java.nio.file.StandardCopyOption; import java.io.IOException; import java . . . '' : Typed variable declaration : Error in method invocation: Static

How do I use directory globbing in JDK7

匆匆过客 提交于 2019-11-30 17:14:49
I have been trying to use the new globbing feature in JDK7, starting from the documentation and examples I can get globs such as "glob:*.dat" to work with the Files.walkFileTree(startingDir, finder); example but I have been unable to get the "**" syntax working. I would like to be able to create something like: matcher = FileSystems.getDefault().getPathMatcher("glob:" + "foo/**/bar/*.dat"); and would be grateful for a simple example. I am using Windows 7. UPDATE: @Oleg and @JBNizet make it clear that the "/" syntax is OS-independent. Note that the Javadocs suggest that OS-dependent syntax is

How do I use directory globbing in JDK7

只谈情不闲聊 提交于 2019-11-29 16:39:24
问题 I have been trying to use the new globbing feature in JDK7, starting from the documentation and examples I can get globs such as "glob:*.dat" to work with the Files.walkFileTree(startingDir, finder); example but I have been unable to get the "**" syntax working. I would like to be able to create something like: matcher = FileSystems.getDefault().getPathMatcher("glob:" + "foo/**/bar/*.dat"); and would be grateful for a simple example. I am using Windows 7. UPDATE: @Oleg and @JBNizet make it

Java File.exists() versus File.isFile()

社会主义新天地 提交于 2019-11-29 11:21:05
I'm unable to think of a realistic use case for the method java.io.File.exists() or its equivalent in Java 7 java.nio.file.Files.exists(Path) . It seems that isFile() or isDirectory() would be preferable in all cases (or canRead() , canWrite() , etc.). For example, in How do I check if a file exists in Java? , the accepted answer seems silly, as the second answer points out. Can anyone give an example where it's useful to know that a thing exists, without knowing whether the thing is a file or directory? EDIT: I understand what File.exists() does. My question is, when would that functionality

Setting/changing the ctime or “Change time” attribute on a file

我的梦境 提交于 2019-11-29 04:32:41
I wish to change the timestamp metadata on files in Java using the java.nio.Files class. I would like to change all 3 Linux/ext4 timestamps (last modified, access, and changed). I am able to change the first two timestamp fields as follows: Files.setLastModifiedTime(pathToMyFile, myCustomTime); Files.setAttribute(pathToMyFile, "basic:lastAccessTime", myCustomTime); However, I am unable modify the last Change: time on the file. Also, it is concerning that there is no change timestamp mentioned in the documentation . The closest available attribute is creationTime , which I tried without any

What is the exact use of java nio package when already methods are available with io package

心已入冬 提交于 2019-11-28 17:12:41
I was learning java nio package and I realized there are lots of methods already provided by File which nio.Files is providing again by using Path class. Like that few more I got. I am actually not getting what is the actual use of nio package. I am just very new to this package so may be my question is wrong but a little help can boost me to read further. The main difference between IO and NIO is that IO is blocking, while NIO is non-blocking. This article explains the differences in the packages and what blocking and non-blocking IO is. Java programming, I/O has until recently been carried

Java File.exists() versus File.isFile()

倖福魔咒の 提交于 2019-11-28 04:21:09
问题 I'm unable to think of a realistic use case for the method java.io.File.exists() or its equivalent in Java 7 java.nio.file.Files.exists(Path). It seems that isFile() or isDirectory() would be preferable in all cases (or canRead() , canWrite() , etc.). For example, in How do I check if a file exists in Java?, the accepted answer seems silly, as the second answer points out. Can anyone give an example where it's useful to know that a thing exists, without knowing whether the thing is a file or

Setting/changing the ctime or “Change time” attribute on a file

纵饮孤独 提交于 2019-11-27 18:27:54
问题 I wish to change the timestamp metadata on files in Java using the java.nio.Files class. I would like to change all 3 Linux/ext4 timestamps (last modified, access, and changed). I am able to change the first two timestamp fields as follows: Files.setLastModifiedTime(pathToMyFile, myCustomTime); Files.setAttribute(pathToMyFile, "basic:lastAccessTime", myCustomTime); However, I am unable modify the last Change: time on the file. Also, it is concerning that there is no change timestamp mentioned

What is the exact use of java nio package when already methods are available with io package

若如初见. 提交于 2019-11-27 10:16:46
问题 I was learning java nio package and I realized there are lots of methods already provided by File which nio.Files is providing again by using Path class. Like that few more I got. I am actually not getting what is the actual use of nio package. I am just very new to this package so may be my question is wrong but a little help can boost me to read further. 回答1: The main difference between IO and NIO is that IO is blocking, while NIO is non-blocking. This article explains the differences in

Watching a Directory for Changes in Java

别说谁变了你拦得住时间么 提交于 2019-11-26 22:07:03
I want to watch a directory for file changes. And I used WatchService in java.nio. I can successfully listen for file created event. But I can't listen for file modify event. I checked official java tutorial , but still struggling. Here is the source code. import static java.nio.file.LinkOption.NOFOLLOW_LINKS; import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; import static java.nio.file.StandardWatchEventKinds.OVERFLOW; import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE; import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; import java.io.File; import