1

I want to do something like this:

File root = new File("C:/file.txt");

but on a folder which is shared on a local network. So lets say the file is on 192.168.1.28 how make it with above command?

Next not working:

File root = new File("//192.168.1.2/file.txt");

File root = new File("\\\\192.168.1.2/file.txt");

File root = new File("\\192.168.1.2/file.txt");

File root = new File("file:\\192.168.1.2/file.txt");

File root = new File("file://192.168.1.2/file.txt");

Thanks a lot.

2
  • I think its possible that java just don't work with networked files like this. Solution would be to copy the file over first then open in java Commented Apr 27, 2012 at 19:42
  • What does this have to do with applets? Can you do it from the command line? Commented Apr 27, 2012 at 21:19

5 Answers 5

1

I think it is possible. However you need to first mount the share using for example Samba - more info here - java read file from network device

Hope it helps

Sign up to request clarification or add additional context in comments.

Comments

1

You can use Apache Commons VFS. It is a library that allow you to manipulate files on various kind of filesystem, one of them perfectly suited for your need is the CIFS file system:

Provides access to the files on a CIFS server, such as a Samba server, or a Windows share.

URI Format

smb://[ username[: password]@] hostname[: port][ absolute-path]

Examples

smb://somehost/home

The provider for CIFS file system is still in development, but you can give it a try. I've already used the library to give transparent access to files via http and ftp protocols.

Comments

0

Java alone doesn't have support for networked file sharing, as the code you're supplying is trying to do.

But if you use a library, like Samba, then you can. But it would be different than the code you showed.

java read file from network device

Comments

0

Java just don't support networked file sharing

Comments

0

With Java 1.8, you can use Java to access files on shared location. Let's say you want to access a .xls file called (Sample.xls) on a shared location.

String location = "\\\your.shared.location.company.com\\folder1\\folder2\\";
String fileName = "Sample.xls";
FileInputStream fis = new FileInputStream(location + fileName);

Comments

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.