Tuesday, 27 January 2015

Create New File in Network folder using JCIFS is an Open Source client library

Here is the code snippet which is used to create file in Network folder with user name and password authentication to local drives. This is done with the help of JCIFS

Maven Dependencies


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import net.sf.jasperreports.engine.JRException;

public boolean createFileInNetworkFolder() {
boolean successful = false;
try {
String userPassword = "UserName" + ":" + "pasword";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(
String newFileName = "sample.txt";
String fileContent = "Just a Test File";
String path = "smb://xxx.xxx.x.xx/files/" + newFileName;
SmbFile sFile = new SmbFile(path, auth);
SmbFileOutputStream sfos = new SmbFileOutputStream(sFile);
successful = true;
} catch (Exception e) {
successful = false;
System.out.println("Problem in Creating New File :" + e);
return successful;


  1. Thanks for the guide, specially the way you've explained the whole thing is just awesome. Thanks for sharing these codes with us, I was looking for creating a new file in network folder using JCIFS but I wasn't able to find any authentic guide about that, Thank to you for this guide I get my solution. Keep up the great work buddy.

    Dental Websites Design is the specialty of OptiMized360.Com

  2. Microsoft office has a different version, and the entire version has the different setup file. Some of the version is Office 2013, Office 2016 and Office 365 etc. Go to www.office.com/setup and redeem your key. Office Com Setup is one of the most popular productivity programs around. If you have your product key handy, you don't even need a disc to start installing Office just visit office setup help. Norton is one of the most reliable antivirus providers in the market to download visit www.norton.com/setup . There are multiple manufacturers making printers for home and office use with varied range as printer series per the need and affordability of different customers. Printer Tech Support. It has become one of the most useful computer hardware devices that allow people to convert computer generated typescript into a physical printed document.

  3. Hi,

    I'm trying to connect to the Windows Share Folder from Linux Server using JCIFS code similar to the above one. Its giving me all kinds of errors like unable to connect etc.
    I just wonder what could be the issue? Can't we connect to Windows share from Linux server? If so, do i install any service/tool in linux to get this code to work?

    I heard something like Samba Server service in Linux which acts as either client or server? I'm not sure what this concept is about. Could you clarify where i'm getting the code to not work as expected.

  4. Nice content..Thank u for sharing these codes sir..I am having a 3 yrs of exp with C++ and Java..Looking for a change these days..And trust me ur all blogs are really really helpful.