File path=new File(".") ? java - file

File path=new File(".") ? What does this code line do ?
File path=new File(args[0]) Does it gives absolute or relative path to the file with name given in args[0]?

your first line will create a Java File object which will point to the current directory i.e. the directory you started your Java program from. You can call isDirectory() on it and you should get true. Read the Java 7 javadocs here.
your second line will create a Java File object which will point to args[0]. It does not verify that the file exists or is readable or writable. This will be checked when you start trying to work with the file.
You can determine the absolute path of a File object using method getAbsolutePath().

Related

How to get file path from a file object in reactJS

I'm trying to pass a file from a form to a hashing function, the only problem is the hashing function takes a file path as an argument, not a file object. So my idea is to choose a file from a normal file input field and then some how extracting the file path from the chosen file.
I tried searching for the file path through the documentation, but i failed to find anything

Using full or relative path in a batch file

I have created a batch script that requires the location of 2 files to be passed into it. I would like it to work regardless of whether the user gives the full file path or relative file path of the files to be read in.
I've tried the following
set Var1=%~dp0%1
set Var2=%~dp0%2
which only works if relative file path is given. Without %~dp0obviously only works if full path is given.
Is there a way for either the full or relative path to be given and for my batch file to work.
Thanks

Loading files into MAGMA

I'm trying to load files into MAGMA and am running into some trouble. Ostensibly, the command load "filename";should be sufficient. I've attempted, but keep getting the same result:
>> load "filename";
^
User error: Could not open file "filename" (No such file or directory)
The file is saved in my documents folder, so I'm not sure what the issue is. Do I have to specify the path? Save the file in a particular place?
I've tried reformatting, using both txt and rtf files, so I don't think that's the issue.
For loading file in MAGMA you can place your file in installed place folder. For example: C:\Program Files (x86)\Magma
Also if your file have an special format you should mention it.
Suppose You want loading a txt file with name a. with load"a"; you face with error. You must type load"a.txt";.
Try using GetCurrentDirectory() command to find your current directory location. And then you can use SetPath() to change where MAGMA has to be to search for your file. This will fix it.

Relative path in C file handling

I need to read file in my program so while providing path I want to give relative paths because all files to be opened will be in some folder within current folder.
I tried this:
FILE *f=fopen("./abc/p.txt","r")
abc is folder withing current folder, but fopen returns NULL. How to do this thing?
This comes from either one of those:
. or ./abc/ is not readable or traversable
./abc/p.txt is not readable
./abc/p.txt does not exist
./abc/p.txt is a broken link
Look at errno to know what's the real problem.
this will run:
FILE *f=fopen("...\\abc\\p.txt","r");

How to get full path of a file just by giving the filename in C?

Suppose I have a file path as C:\Sample\example.txt.
how can full path of the file be retrieved (the file can be in any directory) just by giving the filename i.e., example.txt in C ?
get the source for the "find" command from the (i think) gnu package (or a linux source distribution), and copy the appropriate passages for you platform.

Resources