小编Fur*_*med的帖子

java-该进程无法访问该文件,因为该文件正在被另一个进程使用

我有一段代码可以监视目录中是否有文件添加。每当将新文件添加到目录时,都会选择文件内容并将其发布在kafka上,然后删除该文件。

当我发出单个请求时,此方法有效,但是一旦我将代码接受jMeter的5个或10个用户请求,内容便会成功发布在kafka上,但代码无法删除该文件。我收到一条FileSystemException消息The process cannot access the file because it is being used by another process.

我猜有一些并发问题,我看不到。

public void monitor() throws IOException, InterruptedException {
    Path faxFolder = Paths.get(TEMP_FILE_LOCATION);
    WatchService watchService = FileSystems.getDefault().newWatchService();
    faxFolder.register(watchService, StandardWatchEventKinds.ENTRY_CREATE);
    boolean valid = true;
    do {
        WatchKey watchKey = watchService.take();
        for (WatchEvent<?> event : watchKey.pollEvents()) {
            if (StandardWatchEventKinds.ENTRY_CREATE.equals(event.kind())) {
                String fileName = event.context().toString();
                publishToKafka(new File(TEMP_FILE_LOCATION + fileName).toPath(), "topic");
            }
        }
        valid = watchKey.reset();
    } while (valid);
}

private void publishToKafka(Path path, String topic) …
Run Code Online (Sandbox Code Playgroud)

java file java-8 java.nio.file

6
推荐指数
1
解决办法
3万
查看次数

使用c程序从文件中读取行

#include "stdio.h"

int main(){
    char str[20];
    while(scanf("%19[^\n]",str)==1){
        printf("%s",str);
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译使用:

$ gcc file.c -o file
$ file < input.txt
Run Code Online (Sandbox Code Playgroud)

该程序仅读取文件的第一行input.txt

hello this is
a test that
should make it
happen
Run Code Online (Sandbox Code Playgroud)

我想让程序读取完整的文件,请帮忙

c

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

硒-WebDriver.findElement()和WebElement.findElement()之间的区别

我曾经WebElement.findElement(By.cssSelector('')).click();在页面上找到一个元素,但是它返回"Unable to locate element",但是当我使用WebDriver.findElement(By.cssSelector('')).click();它时,它能够找到该元素并单击它。

我无法理解findElement()两个接口之间的区别。请帮助。

java testing selenium

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

websphere - CWWKE0054E错误无法打开文件

我正在尝试从命令行运行websphere liberty配置文件服务器.我按照这里告诉的步骤操作:https://developer.ibm.com/wasdev/downloads/liberty-profile-using-non-eclipse-environments/

我创建了名为server1的服务器.

但是当提取完成并且我尝试使用命令启动服务器时: server start server1

服务器抛出错误:CWWKE0054E: Unable to open file C:\wlp\wlp\usr\servers\server1\logs\C:\Users\Furquan\AppData\Local\Temp\\ihp_custom_batches.log..现在我知道这不是一条有效的道路,但我不知道在哪里以及如何改变它.请帮忙 !!

java websphere command-line websphere-liberty server

0
推荐指数
1
解决办法
900
查看次数

使用递归创建二叉树时的C - 分割错误

我试图编写一个使用C中的指针创建二叉树的简单程序,但我无法找到此代码的问题.我在第二次插入时收到Segmentation Fault.

该程序接受五个数字的输入,然后使用数组输入创建一个二叉树.示例运行:

这是程序的输出

输入5个元素:

45 78 89 32 46

在generateBST中

在插入中转到右侧子树

插入

分段故障

请帮我解决这个错误.谢谢.

#include <stdio.h>
#include <stdlib.h>

typedef struct node {
    int value;
    struct node * lst;
    struct node * rst;
}Node;

void printBST(Node *root){
    puts("In printBST");
    if(root == NULL){
        return;
    }
    printBST(root->lst);
    printf(" %d ", root->value);
    printBST(root->rst);
}

void insert(Node **root, int element){
    puts("In insert");
    if((*root)->value > element){
        puts("Going to left sub tree");
        insert(&(*root)->lst ,element);
    } else if ((*root)->value < element) {
        puts("Going to right sub tree"); …
Run Code Online (Sandbox Code Playgroud)

c pointers segmentation-fault binary-search-tree

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