I'm testing a web app with selenium and I run the test on a remote XP VM. In my test, I douwnload a file and I want to compare this file with a local one. Can I compare these two files :
This is a part of the code :
//the local file path
File file1 = new File("C:/export_transaction.csv");
//the remote file path
File file2 = new File("C:/Documents and Settings/Export_Transaction.csv");
Properties prop1 = new Properties();
Properties prop2 = new Properties();
prop1.load(new FileReader(file1));
prop2.load(new FileReader(file2));
Assert.assertEquals(prop1, prop2);
The problem is that I can't access to the remote file path. Is there a way to specify the path of the remote file ?
Please help !
Related
I want upload multiple file from Windows share folder server (e.g. //server_name/folder/)
to my HDFS using Java
list of methods I have tried
org.apache.hadoop.fs.FileUtil set input path = //server_name/folder/
it says java.io.FileNotFoundException: File //server_name/folder/ does not exist
FileSystem.copyFromLocalFile (i think this is from local hadoop server to hdfs server)
IOUtils.copyBytes same as fileUtil >> file does not exist
a simple File.renameTo same as fileUtil >> file does not exist
String source_path = "\\server_name\folder\xxx.txt";
String hdfs_path = "hdfs://HADOOP_SERVER_NAME:Port/myfile/xxx.txt";
File srcFile = new File(source_path);
File dstFile = new File(hdfs_path);
srcFile.renameTo(dstFile);
Do I need to create FTP or How about using FTPFileSystem?
Or anyone have better solution Or Sample Code
thank you
FileSystem has copyFromLocal method:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
Configuration configuration = new Configuration();
configuration.set("fs.defaultFS", "hdfs://abc:9000");
FileSystem fs= FileSystem.get(configuration);
fs.copyFromLocalFile(new Path("/source/directory/"),
new Path("/user/hadoop/dir"));
Hi I have a java eclipse project which I want to execute from command line. I made a jar of it and am running it from command line.
I figured out how to access a file in a Jar by using getresourceasstream.
Ex:
InputStream is = Extractor.class.getResourceAsStream("CompanyNameListModified.txt");
BufferedReader in=new BufferedReader(new InputStreamReader(is));`
What I wanna know now is how to access a directory from jar .
Currently:
Runtime.getRuntime().exec("hadoop fs -get /tmp/stockmarkets/ localfile");
File dir = new File("/home/hadoop/project/localfile");`
This gives a filenotfoundexception.
What I want to do is
File[] directoryListing = dir.listFiles();
if (directoryListing != null) {
for (File child : directoryListing) {
....
}
}
Hence goto the directory and loop over each file in that directory.. How should I do it so it works for my JAR.?
So I tried this:
Runtime.getRuntime().exec("hadoop fs -get /tmp/stockmarkets/ localfile");
File dir =new File(Extractor.class.getResource("/home/hadoop/project/localfile").getPath());
error:
Exception in thread "main" java.lang.NullPointerException
I checked my directory it does have the local file directory.
You have to provide a filesystem path to use as a property
java -jar yourprogram.jar -DworkDir=/home/hadoop/project
or command-line argument, and then use that in both the call to hadoop and the File declaration.
I really have a problem while trying to upload a file into my servers root directory. I know that the File-Class cannot handle directorys like http://localhost:8080/rootdata.
Please do not tell me not to upload files to the root. I just want to know how to do that.
So is there a way bringing up my files in that root directory via java?
Thanks for any help
Use Apache's FTP library to browse and retrieve files from your servers filesystem. You can list out all the files in the root directory by using:
.listFiles()
Example:
String hostname = properties.getProperty("FTP_SERVER");
String user = properties.getProperty("FTP_USER");
String passwd = properties.getProperty("FTP_PASSWD");
FTPClient client = new FTPClient();
client.connect(hostname);
client.login(user, passwd);
String reply = client.getStatus();
System.out.println(reply);
client.enterRemotePassiveMode();
client.changeWorkingDirectory("/");
FTPFile[] files = client.listFiles();
I am not familiar with Windows shared folders, but here is what I have:
filePath = //server/TEMP/ **(1)**
server = another machine. TEMP = shared folder.
If I open this line with Explorer it goes to
http://server/TEMP/
and I can see list of files and create new.
If I change
filePath = \\server\TEMP\ **(2)**
(slashes replacement) I CAN'T open this directory.
in java code (1.6) I have
File f = new File(filePath);
where filePath can be (1) or (2) - no matters, after creating the File object its .toString() gives me
\\server\TEMP\ (2)
which CAN'T execute .createNewFile() with this exception:
java.io.IOException: The network path was not found at
java.io.WinNTFileSystem.createFileExclusively(Native Method) at
java.io.File.createNewFile(Unknown Source)
How to say to java not to convert my slashes? or how to create file without java.io.File?
Thanks,
Roman.
I have created an applet to read some info from a file on the server. I try to access the file using the following code:
Properties Settings = new Properties();
settings.load(new URL(getDocumentBase(), "settings.ini")).openStream());
All of a sudden, the second line is giving me the error:
java.lang.NullPointerException
at java.applet.Applet.getDocumentBase(Unknown Source)
My applet is signed and I access it through my localhost.Why can't I use getDocumentBase anymore?
Btw, I am using Netbeans Web Start option to create the necessary files (jars, html, jnlp) and then move them to my IIS local server.
SOLUTION
I'm loading the ini file from within the jar now:
Properties Settings = new Properties();
URL url = this.getClass().getResource("/myapplet/settings.ini");
settings.load(url.openStream());
At first glance I would expect:
new URL(getCodeBase(), "settings.ini")
as getCodeBase gives the directory URL, getDocumentBase gives the HTML URL.
That it worked previously is astonishing. Maybe the HTML URL ended with ?... and you read the HTML page?
SOLUTION
I'm loading the ini file from within the jar now:
Properties Settings = new Properties();
URL url = this.getClass().getResource("/myapplet/settings.ini");
settings.load(url.openStream());