Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
读取文件';从Eclipse中的条件JAVA断点表达式中删除内容,而不创建变量_Java_Eclipse_Debugging_File Io_Conditional Breakpoint - Fatal编程技术网

读取文件';从Eclipse中的条件JAVA断点表达式中删除内容,而不创建变量

读取文件';从Eclipse中的条件JAVA断点表达式中删除内容,而不创建变量,java,eclipse,debugging,file-io,conditional-breakpoint,Java,Eclipse,Debugging,File Io,Conditional Breakpoint,在Eclipse中,如何从条件JAVA断点的表达式中读取文件内容 当字符串变量的值包含“收益”时,我的断点条件为true: myVariable!=null&&myVariable.contains(“收益”) 我想要一个条件断点来替换字符串的内容(如果为true);但是,我只能通过等待JVM中断(在断点处),然后显示以下块(Ctrl+Shift+D)来实现这一点。块将文件内容读入myVariable String sCurrentLine, fileName = "modified-earni

在Eclipse中,如何从条件JAVA断点的表达式中读取文件内容

当字符串变量的值包含“收益”时,我的断点条件为true:

myVariable!=null&&myVariable.contains(“收益”)

我想要一个条件断点来替换字符串的内容(如果为true);但是,我只能通过等待JVM中断(在断点处),然后显示以下块(Ctrl+Shift+D)来实现这一点。块将文件内容读入
myVariable

String sCurrentLine, fileName = "modified-earnings.xml";

java.lang.StringBuffer sb = new java.lang.StringBuffer();
java.io.FileReader fr = new java.io.FileReader(fileName);

java.io.BufferedReader br = new java.io.BufferedReader(fr);
while ((sCurrentLine = br.readLine()) != null) {
    sb.append(sCurrentLine + System.getProperty("line.separator"));
}
fr.close();
// this is where my variable gets the new value from a file
myVariable = sb.toString();
br.close();
正如您所看到的,每次我要替换字符串的值时都要计算这些行有点麻烦,所以我希望调试器使用与断点相同的条件性质来为我执行。注意附加的(最后一个)布尔表达式
(myVariable=magicCode(“modified earnings.xml”)!=空

myVariable!=null&&myVariable.contains(“收益”)
&&(myVariable=magicCode(“modified earnings.xml”)!=空

我缺少的是不能编码的magicCode函数,因为我不能(重复不能)更改代码或向类路径添加新JAR。理想情况下,系统API可以做到这一点:

myVariable = StreamToString.do(System.getResourceAsStream("modified-earnings.xml"))

对于Java8
此eclipse断点条件代码检查文件
c:/temp/hello.txt
中的内容
hello

"hello".equals(new String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get("c:/temp/hello.txt"))))