Open a text file in the default text editor… via Java?

后端 未结 3 788
陌清茗
陌清茗 2020-12-01 05:43

OK. Simple question. Maybe not so simple answer, though:

I have a file I downloaded in Java, and I know that it\'s a text file. Is there any way that I can use Java

3条回答
  •  难免孤独
    2020-12-01 06:03

    Certainly you could configure in the text editor and use Runtime.exec to start it. But I can't think of any way to determine the default editor, especially in a system-independent fashion.

    Maybe your best option is to identify which of the several most popular platforms you're on and then find a way to start the default editor on that platform. Eg, on Window you'll get the default editor if you do "start filename.txt", and I'm pretty sure there's a Linux equivalent.

提交回复
热议问题