小编use*_*404的帖子

Runtime.getRuntime().exec(cmd)挂起

我正在执行一个命令,它返回一个文件的修订号; '文件名'.但是如果执行命令时出现问题,则应用程序会挂起.我该怎么做才能避免这种情况?请在下面找到我的代码.

String cmd= "cmd /C si viewhistory --fields=revision --project="+fileName; 
Process p = Runtime.getRuntime().exec(cmd) ;  
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));  
String line = null; 
while ((line = in.readLine()) != null) {  
System.out.println(line);  
} 

} catch (Exception e) {  
e.printStackTrace();  
 }
Run Code Online (Sandbox Code Playgroud)

java process runtime.exec processbuilder

13
推荐指数
2
解决办法
2万
查看次数

写入java中的临时文件

我想以追加模式写入临时文件.我看到文件已创建,但Stringbuffer中的数据未写入.有人可以告诉我为什么吗?请在下面找到我写的代码,

public static void writeToFile(String pFilename, StringBuffer sb)
        throws IOException {

    String property = "java.io.tmpdir";


    String tempDir = System.getProperty(property);

    File dir = new File(tempDir);
    File filename = File.createTempFile(pFilename, ".tmp", dir);
    FileWriter fileWriter = new FileWriter(filename.getName(), true);
    System.out.println(filename.getName());
    BufferedWriter bw = new BufferedWriter(fileWriter);
    bw.write(sb.toString());
    bw.close();
}
Run Code Online (Sandbox Code Playgroud)

java

8
推荐指数
2
解决办法
2万
查看次数

使用Java从Filename获取filePath

是否有一种简单的方法来获取filePath我知道文件名?

java file filepath

6
推荐指数
4
解决办法
10万
查看次数

从 Eclipse 插件中的文件读取

我需要从 eclipse 的属性文件中读取配置详细信息。我已将其放在与 我调用的类文件config.properties相同的级别plugin.xml中:

Properties properties = new Properties();
FileInputStream file;
String path = "./config.properties";
file = new FileInputStream(path);
properties.load(file);
Run Code Online (Sandbox Code Playgroud)

我得到一个file not found exception. 有没有更好的方法来做到这一点?

java eclipse eclipse-plugin

5
推荐指数
1
解决办法
4698
查看次数

退货声明不起作用

有人可以帮我修复我的问题.我有一个函数,它检查特定路径中是​​否存在文件.该函数检查文件名是否匹配,路径是否也匹配.(具有特定名称的文件可能存在于多个位置).请在下面找到我的代码.

memberPath是一个包含相对路径的静态变量.file_Path是一个静态变量,在找到匹配项后会更新.

我的问题是函数找到了匹配,但它突然出现for循环返回语句但返回到for循环.有人可以帮我修改我的代码,这样一旦找到匹配,它就会将bac返回到调用位置.

public static String traverse(String path, String filename) {
        String filePath = null;
        File root = new File(path);
        File[] list = root.listFiles();

        for (File f : list) {
            if (f.isDirectory()) {
                traverse(f.getAbsolutePath(), filename);
            } else if (f.getName().equalsIgnoreCase(filename) && f.getAbsolutePath().endsWith(memberPath)) {
                filePath = f.getAbsolutePath();
                file_Path = filePath;
                break ;
                }
        }
        return filePath;
}
Run Code Online (Sandbox Code Playgroud)

java

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