> 1) Java program knows the name of pdf file when run; but I don't.
How do you want to open something you don't know even its name? You need
at least the name of the PDF file. If you don't even know that, then try black
magic.
> 2) If I use Linux, or Apple... a batch file doesn't work.
Opening a file through the standard mechanism the operating system
provides is a task that can be done with Java, but is not a task that
Java abstracts in any way. You need to write platform DEPENDANT code. On
an Apple (>= OSX !) you have the "open" command to open a file by
filetype, on Windows you can invoke the "start" command to open a file
by extension, on Linux, I don't know a way yet. But important is: Java
does not abstract you from this kind of work, at least not in 1.4.2. You
need to write your own os-dependant code for that.
If you want to do that approach, then you can use this class for WIndows
and Appe:
public class Executable {
public static final Process openDocument(final String fileName, boolean
waitForTermination) throws IOException {
Process process = null;
if (OperatingSystem.isWindows())
process = Runtime.getRuntime().exec("cmd /c start \"\" \"" + fileName +
"\"");
else
if (OperatingSystem.isMac())
process = Runtime.getRuntime().exec(new String[] { "/usr/bin/open",
fileName });
try {
if (process != null && waitForTermination)
process.waitFor();
}
catch (InterruptedException ie) { }
return process;
}
public static final Process openDocument(File file, boolean
waitForTermination) throws IOException {
return openDocument(file.getAbsolutePath(), waitForTermination);
}
}
public class OperatingSystem {
public static boolean isWindows() {
String os = System.getProperty("os.name").toLowerCase();
return os.indexOf("windows") != -1 || os.indexOf("nt") != -1;
}
public static boolean isMac() {
String os = System.getProperty("os.name").toLowerCase();
return os.indexOf("mac") != -1;
}
public static boolean isLinux() {
String os = System.getProperty("os.name").toLowerCase();
return os.indexOf("linux") != -1;
}
}
It was Fri, 1 Apr 2005 13:03:44 +0200, a beautiful sunny day, until "Marco"
<[EMAIL PROTECTED]> wrote this:
> > don't know if this works for java but if you "call" your PDF from within a
> > batch file the associated application is started on Windows
>
>
> This is not ok for me, because:
>
> 1) Java program knows the name of pdf file when run; but I don't.
> 2) If I use Linux, or Apple... a batch file doesn't work.
>
> Thank you
>
> Marco
>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by Demarc:
> A global provider of Threat Management Solutions.
> Download our HomeAdmin security software for free today!
> http://www.demarc.com/Info/Sentarus/hamr30
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
/*
* Roger Misteli - ABACUS Research AG
* email: [EMAIL PROTECTED]
* Klingon function calls do not have 'parameters' - they have 'arguments'..
* and they ALWAYS WIN THEM.
*/
-------------------------------------------------------
This SF.net email is sponsored by Demarc:
A global provider of Threat Management Solutions.
Download our HomeAdmin security software for free today!
http://www.demarc.com/Info/Sentarus/hamr30
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions