【发布时间】:2018-10-30 07:36:29
【问题描述】:
以下是我的 Java 代码
import java.io.*;
public class UnderLine {
public static void main(String[] args) throws Exception {
String thisLine = null;
String Test = "Hello";
try {
// open input stream test.txt for reading purpose.
BufferedReader br = new BufferedReader(new FileReader("F:\\Java\\Testprojects\\UnderLine.java"));
while ((thisLine = br.readLine()) != null) {
if(thisLine==" String Test = \"Hello\";\n") {
// underLine the line which has String test
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
在上面的代码中,我通过给出它的路径来读取相同的源代码。我想用
在代码行下划线(单词下面的红线,好像发生了正常的代码错误)String Test = "Hello";.
我该怎么做?
【问题讨论】:
-
你想给你的代码加下划线吗?目的是什么?
-
@HamishD 我想知道当程序中发生错误时(编译前),字符串如何以红色下划线显示
-
它是您使用的任何 IDE 的一部分,而不是代码。如果你用记事本打开代码,就没有红线了。
-
@HamishD 是的,我想用我的程序实现那个 IDE 功能,我该怎么做?
-
无法将函数用于您自己的没有错误的代码。你需要它的目的是什么?