I have an xp box with file sharing open and can access files through the LAN, but how do I do this in Java?
currently I have:
which works perfectly in allowing me to list the file, but say the file is some movie.avi, or a program.exe, how do I tell Java to execute that file using the default program?
Basically what I'm looking for is exactly like:
Only this time I'm using SmbFile to allow credentials (and thus log into a share server).
Is there a SmbDesktop or something?
It seems like this should be very easy: I have access to the file... all I want to do is run it.
Zachary Wilson wrote:It seems like this should be very easy: I have access to the file... all I want to do is run it.
Let's clarify that "easy" question: It isn't "you" which has access to the file, it's your Java code. And it isn't "you" which would run it, it would be the operating system.
Now that we have a clearer (but less "easy") question, we have a clearer answer. Your Java code has access to the file, but the operating system doesn't. But you want the operating system to run the file. Does that help?
So I need to find a way to transfer access from my java file to the current operating system, or have the operating system read through the java; I have no idea how to do that: I'm thinking read each byte and transfer it somehow, but as far as the actual code to accomplish this: I do not know.
What you might be able to try is using Runtime.exec(...) to request the operating system execute or open the file. However, Runtime.exec has a laundry list of issues itself. See http://www.javaworld.com/jw-12-2000/jw-1229-traps.html for a short list; I am sure others on the forum will also pipe in on the evils of Runtime.exec(...)
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Is it possible to stream the file? For example, when I tell xp to open a file in //sharename/filename.exe , it reads it from the source rather than copying it to my local computer (given the file can be a large movie, yet it still begins playing it instantly)
In using Runtime.exec() I need to provide credential to execute any file, and I'm trying to avoid a "net use \\192...." as it is windows specific.
It would be beautiful if there was a Desktop.getDesktop().open(SmbFile).
Right now I have:
which is compatible with Java.io, and I can read the file line by line, but how to I execute it with a default editor/program ?
Zachary Wilson wrote:Is it possible to stream the file?
I suppose if "executing the file" supported some kind of streaming mode, and your program could somehow insert itself into the "executing the file" process, then it might be possible. But that would involve modifying the operating system to call your class to "execute" the file. So no, I don't think that's too likely. Besides which it would be operating-system specific, and you said you didn't want that.
Remember, when you call Desktop.getDesktop().open(X), you're just telling the O/S to open the file X. Your Java program isn't anywhere in the picture when that opening takes place.
Zachary Wilson wrote:Right, but when I call Desktop.getDesktop().open(X), X is a Java.io.File object that is being executed by the O/S.
You're skipping the important details again. Sure, you pass a File object to that method. But of course the O/S function which opens a file has no idea what a java.io.File object is. Internally the "open" method must get the path to the file -- which is just a string -- and pass that to the O/S function. The O/S function doesn't use any code and doesn't know anything about any Java objects. Any theory which has O/S code knowing anything about Java is an incorrect theory.