2

I should open a .txt file on my java application, so i've searched a way to do this but what i've found is only java calls to operating system, writing console commands. There is a way to open a .txt file independently of operating system of the user? Note that I want to open an application that reads .txt, not only its content! I'm wondering if there is a way to call default application for reading .txt, without write for example "notepad myTxt.txt" on console from java :)

tshepang
  • 10,772
  • 21
  • 84
  • 127
Andrea Tucci
  • 187
  • 1
  • 8

2 Answers2

2

You can use Desktop.open()

From the Javadocs:

Launches the associated application to open the file.

http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html#open(java.io.File)

An alternative (because you mentioned "editing") might also be Desktop.edit()

a_horse_with_no_name
  • 440,273
  • 77
  • 685
  • 758
0

You'll most likely want to use: FileReader and BufferedReader classes that work on any platform that Java supports. In fact, because Java runs on a virtual machine, simple IO is inherently platorm, OS independent. See this reference for ideas.

Chimera
  • 5,552
  • 6
  • 41
  • 77