[jcifs] Printing

Ykä Huhtala Yka.Huhtala at cdgroup.fi
Tue May 14 22:58:04 EST 2002


Hi,

Is there an example code on how to print to a shared printer. First I wrote
the following small program:

    public static void print(String filename, String share)
	throws Exception
    {
	try {
	    jcifs.Config.setProperty("wins", "192.168.1.1");
	    PrintWriter out = new PrintWriter(new SmbFileOutputStream(share));
	    FileReader in = new FileReader(filename);
	    int c;
	    while ((c = in.read()) != -1) {
		out.write(c);
	    }
	    out.close();
	} catch(Exception e) {e.printStackTrace();}
    }

Next, I tried printing using the Put program under the example files, but
unfortunately it also failed. As a result in both cases, I get an Invalid
parameter exception:

Exception in thread "main" jcifs.smb.SmbException: Invalid parameter
	at jcifs.smb.SmbTransport.send(SmbTransport.java:495)
	at jcifs.smb.SmbSession.send(SmbSession.java:135)
	at jcifs.smb.SmbTree.send(SmbTree.java:91)
	at jcifs.smb.SmbFile.send(SmbFile.java:499)
	at jcifs.smb.SmbFile.open(SmbFile.java:555)
	at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:107)
	at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:92)
	at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:62)
	at Put.main(Put.java:30)

Printing works fine, for example, with Samba smbclient's print command. The
share URL that I'm trying to use is
smb://user:password@server/Printer
where Printer is share name of the printer at the server. Any ideas?

Cheers, Yka





More information about the jcifs mailing list