0

i know that to open an application say notepad the following command is enough

ProcessBuilder proc=new ProcessBuilder("notepad.exe"); and executing

proc.start(); notepad open`s up an untitled file.

But i read that using processbuilder we can open a particular file in notepad with following command ProcessBuilder proc=new ProcessBuilder("notepad.exe","sample");

proc.start(); executing this

if a sample.txt notepad file doesnt exist in the system, notepad would open up and shows a message window asking that "sample.txt doesnt exist, do you want to create?". Well that condition is fine with me.

But before executing proc.start(); if i create a sample.txt file and save it in my desktop. And then upon executing proc.start(); shouldnt the file named sample open up in notepad and show me its content. Rather its still asking me to "do you want to create sample.txt". why is that so even if i had already created the same file before execution ?

4
  • 2
    Are you sure you're in the right working directory? And did you create the file in a separate process, or in the same? Commented May 30, 2015 at 15:50
  • 1
    You pass "sample" in the code sample, but it's "sample.txt" (with .txt) in the error message. Could this be the problem? I mean check if the file you are creating manually and programmatically has the same name. And yes, make sure you're in the right working directory or pass the full path to the process. Commented May 30, 2015 at 15:59
  • Consider not even using Process or ProcessBuilder but rather using Desktop as per this question. Commented May 30, 2015 at 16:23
  • Well directory was the problem.. and thanks. when i saved sample.txt file in my program`s class folder it worked. I wonder how to open the sample.txt file which is somewhere else and not inside my program class folder. How should i code Commented Jun 1, 2015 at 15:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.