Accessing mounted linux directory from windows2000 using java


Hi Experts,


I am trying to access and copy a local windows2000 file to a certain mounted linux directory...

May I ask how to do this in java...?   A sample code would be best...


Thanks in advance experts..!  =)
aris_datuinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
Use the File class and pass it the name of the file by using the proper protocol, something like:

File f = new File("\\\\machinename\\foldername\\filename");

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dejan PažinHead of SW DevelopmentCommented:
Here is the complete code that copies win file to a mounted linux directory (the directory is mounted over Samba):

public class FileCopy
{
  public static byte[] readBytes(File file) throws IOException
  {
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
    long length = file.length();
    byte[] bytes = new byte[(int) length];
    bis.read(bytes);
    bis.close();
    return bytes;
  }

  public static void writeBytes(byte[] bytes, File file) throws IOException
  {
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
    bos.write(bytes);
    bos.close();
  }

  public static void main(String[] args)
  {
   
    File inFile = new File("C:\\original\\test.txt");
    File outFile = new File("Z:\\your\\mounted\\linux_direcory\\copiedTest.txt");
    try
    {
      byte[] readBytes = readBytes(inFile);
      writeBytes(readBytes, outFile);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}
0
CEHJCommented:
How is the linux file connected with Windows as far as the network is concerned?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

aris_datuinAuthor Commented:
I plan to setup a samba account for my linux accessibity from windows to a certain mounted linux directory...   Then I plan to map the mounted linux directory using the samba account...    Hope this plan will work...

Then if dejanpazin code will work, then I think my problem is solved...    Hope I am not missing out something here...

Thanks again in advanced...   =)
0
girionisCommented:
If all esle fails you might use the Runtime.getRuntime().exec() method and read the input. This *should* work.
0
girionisCommented:
I'd say split points between me and dejanpazin.
0
CEHJCommented:
Yep - no problem. Count me out - it should work
0
Dejan PažinHead of SW DevelopmentCommented:
OK with me.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.