小编dam*_*ina的帖子

无法使用Java删除Windows中的文件

我一直在尝试使用Java IO file.delete()API 删除Windows操作系统中的文件.但是它失败并返回false.相同的代码就像Ubuntu中的魅力一样.

我已经验证该文件的权限允许程序删除它.此外,文件的所有输入和输出流都已尝试使用资源打开.

try (InputStream in = new FileInputStream(localFile); OutputStream out = new FileOutputStream(destinationFileName))

使用我已经测试过的调试器,发现在代码行中我删除了它true为以下API调用返回的文件.

file.exists()
file.canRead();
file.canWrite();
file.canExecute();
Run Code Online (Sandbox Code Playgroud)

我甚至尝试System.gc()在调用delete之前添加,以确保所有流都关闭.

不确定这是否是有用的信息,但我甚至尝试使用Apache commons FileUtils.forceDelete(file)方法,它也失败了.

那我在这里错过了什么?

更新:

通过使用Files.delete(Paths.get(file.getAbsolutePath()))我得到以下错误.

java.nio.file.FileSystemException: C:\Users\thuvvareka\Desktop\temp\in\sd.xml: The process cannot access the file because it is being used by another process.
    at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
    at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
    at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
    at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:269)
    at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
    at java.nio.file.Files.delete(Files.java:1126)
    at org.adroitlogic.x.transport.file.FileMessageInjector.finalizeProcessing(FileMessageInjector.java:161)
    at org.adroitlogic.x.transport.file.FileMessageInjector.afterProcess(FileMessageInjector.java:123)
    at org.adroitlogic.x.transport.file.FileMessageInjector.afterProcess(FileMessageInjector.java:37)
    at org.adroitlogic.x.base.trp.ScheduledMessageInjector.lambda$2(ScheduledMessageInjector.java:72)
    at org.adroitlogic.x.api.trp.MessageReceiver.lambda$receive$3(MessageReceiver.java:100)
    at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:760)
    at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:736)
    at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474) …
Run Code Online (Sandbox Code Playgroud)

java windows io file ultraesb

7
推荐指数
1
解决办法
2854
查看次数

ActiveMQ以编程方式设置传输参数

是否可以设置ActiveMQ传输参数,例如maxReconnectAttempts在运行时使用Java API?

在我的情况下,我最初通过提供基本故障转移URL故障转移来创建ActiveMQ连接工厂:

ActiveMQSslConnectionFactory connectionFactory = new ActiveMQSslConnectionFactory("(ssl://192.168.1.112:61617,ssl://192.168.1.112:61619)?randomize=false")

但是后来我需要将传输参数设置为此连接工厂,例如maxReconnectAttempts.可能吗?

java activemq-classic ultraesb

2
推荐指数
1
解决办法
699
查看次数

标签 统计

java ×2

ultraesb ×2

activemq-classic ×1

file ×1

io ×1

windows ×1