[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Accessing mounted linux directory from windows2000 using java

Posted on 2004-11-17
11
Medium Priority
?
213 Views
Last Modified: 2010-03-31

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..!  =)
0
Comment
Question by:aris_datuin
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 132 total points
ID: 12612671
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
 
LVL 17

Assisted Solution

by:Dejan Pažin
Dejan Pažin earned 128 total points
ID: 12612859
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12617988
How is the linux file connected with Windows as far as the network is concerned?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:aris_datuin
ID: 12621580
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
 
LVL 35

Expert Comment

by:girionis
ID: 12622607
If all esle fails you might use the Runtime.getRuntime().exec() method and read the input. This *should* work.
0
 
LVL 35

Expert Comment

by:girionis
ID: 12800926
I'd say split points between me and dejanpazin.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12800949
Yep - no problem. Count me out - it should work
0
 
LVL 17

Expert Comment

by:Dejan Pažin
ID: 12801352
OK with me.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month18 days, 20 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question