UsamaJawad96
UsamaJawad96

Reputation: 3

How to copy file from local directory in another drive to HDFS in Apache Hadoop?

I'm new to Apache Hadoop and I'm trying to copy a simple text file from my local directory to HDFS on Hadoop, which is up and running. However, Hadoop is installed in D: while my file is in C:.

If I use the -put or copyFromLocal command in cmd with the file in the aforementioned drive, it doesn't allow me to do that. However, if I place the text file in the same D: drive, the file is correctly uploaded to Hadoop and can be seen on Hadoop localhost. The code that works with the file and Hadoop in the same drive is as follows:

hadoop fs -put /test.txt /user/testDirectory

If my file is in a separate drive, I get the error '/test.txt': No such file or directory. I've tried variations of /C/pathOfFile/test.txt but to no avail, so in short, I need to know how to access a local file in another directory, specifically with respect to the -put command. Any help for this probably amateurish question will be appreciated.

Upvotes: 0

Views: 2019

Answers (2)

OneCricketeer
OneCricketeer

Reputation: 191701

If your current cmd session is in D:\, then your command would look at the root of that drive

You could try prefixing the path

file:/C:/test.txt

Otherwise, cd to the path containing your file first, then just -put test.txt or -put .\test.txt

Note: HDFS doesn't know about the difference between C and D unless you actually set fs.defaultFS to be something like file:/D:/hdfs

Upvotes: 0

Theofanis
Theofanis

Reputation: 303

From your question I assume that you have installed Hadoop in a Virtual Machine (VM) on a Windows installation. Please provide more details on that if this assumption is incorrect. The issue is that your VM considers drive D: as the Local Directory, where -put and -copyFromLocal can see files at. C: is not visible to these commands currently.

You need to mount drive C: to your VM, in order to make its files available as local for Hadoop. There are guides out there depending on your VM. I advise care while at it, in order not to mishandle any Windows installation files.

Upvotes: 0

Related Questions