读取文件';从Eclipse中的条件JAVA断点表达式中删除内容,而不创建变量
在Eclipse中,如何从条件JAVA断点的表达式中读取文件内容 当字符串变量的值包含“收益”时,我的断点条件为true:读取文件';从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
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"))))