简体   繁体   中英

Is it possible to highlight strings in a *.txt file using Java?

I wrote a "search" function as part of a program I'm working on. At the moment, I have it set to output where it found the searched word (every occurrence) to the console. What I want it to do now is open the file in Notepad (already know how) and to highlight every occurrence of the searched word.

Everywhere I've looked I see frames and text-areas, which is no good for me at the moment because I don't know any GUI coding yet.

The txt fileformat does not support any kind of formatting, so you cannot highlight anything in the traditional way. So the options you are left with is:

  • you can use underscores
  • or you can use FULL-UPPERCASE
  • or you can use ** stars **

or similar approaches that depend on basic characters available in the used characterset.

Short answer: NO

Backdoor : Create your own Notepad like java app using swing that will support the required features. You may say that creating this app is teadious but who says you have to create all the features...Just the basic ones will be fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM