I have a function that gets a file path as an input. input file is located in a folder in my project (etc/xsd/template.xsd). how can i set this path?
this ia my function:
JAXBUtilityTool tool = new JAXBUtilityTool("etc/xsd/template.xsd","src.com.classes");
and it can not find the file "etc/xsd/template.xsd"
System.getProperty("user.dir") does not help since when I add the rest of path to it:
System.getProperty("user.dir")+ "etc/xsd/template.xsd"
result is c:\eclipse\myworkingdirectory\project/etc/xsd/template.xsd
Try:
String path = System.getProperty("user.dir");
path = path.replaceAll("\\","/") + "/etc/xsd/template.xsd"
Source:
String.replaceAll single backslashes with double backslashes
Related
Im using jgit, log() command, and the addPath(String path) requires me to input a git compatible path, that is, a relative path like src/java/com/foo/Test.java. But what I got is a File object, that will have an absolute path of something like: c:\hello\irrelevant\myproject\src\java\com\foo\test.java.
How to convert from this to the git path? Is there some handy function within jgit itself? I cant find it....
You can use Path::relativize to get the relative path between the file to add and the work directory.
For example:
File workDir = git.getWorkTree(); // e.g. "/path/to/workdir"
File file = new File("/path/to/workdir/foo.txt");
Path relativePath = workDir.toPath().relativize(file.toPath());
assertEquals("foo.txt", relativePath.toString());
I have few directorates and one file *.txt under one Directory A, Directory path is in QString
say c:/A/1/2/3/4
c:B/C/A/1/2/3/4/5/6
In my code I have only the full path, now I want to get the directory until A(name of A can change anytime) based on the file *.txt
inshort:- I want to parse all directory and get the directory until the place where *.txt present from right to left
Are you trying to get the string of the file path to A? Ex. If the file path was:
C:/Users/Admin/Desktop/file.txt
you want to get:
C:/Users
If so, all you have to do is find the second index location of "/". You could do something like this:
QString filePath = "C:/Users/Admin/Desktop/file.txt";
int index = filePath.indexOf("/");
index = filePath.indexOf("/",index+1);
QString shortenedPath = filePath.mid(0,index);
This should give you:
C:/Users/
If that isn't what you meant, then sorry for the long response.
I am trying to save an image to server.Server directory structure is as follows
httpdocs-
Folder-
Page.aspx
and
httpdocs-
Images-
Subimages
The Folder and Images are under the httpdocs. I need to save the image to subimages folder from pages.aspx. Saving image code is on pages.aspx.
I tried
string CroppedImagePath = Server.MapPath("~/Images/Subimages"+file)
But not get the exact result
Unless file contains a leading / character, that's going to end up saving as something like:
~/Images/Subimagesfilename.ext
Use Path.Combine() to build a path name. Something like this:
var CroppedImagePath = Path.Combine(Server.MapPath("~/Images/Subimages"), file);
try this
string CroppedImagePath = Server.MapPath("~/Images/Subimages/"+file)
/ after Subimages
I have 3 jars: jar1, jar2 and jar3, in the same path who can change in other pc (ex: c:\prova)
When I run jar1, it moves jar2 in the Windows Sturtup folder.
I want that jar2 simply activate jar3 at every windows startup, but of course it doesn't find jar3 who is remained in the first path.
So I want that jar1 pass a reference (in this case the path c:\prova) to the jar2, when moving it, or at least on the first call to it.
I find it difficoult because:
I can't write the path in a text file in jar2: text files in jars aren't writable.
I can't write the text file in the windows Startup folder: it will be opened at every win startup..
I can't pass the path as a parameter, it will be good for the first call but I can't store this value for the succesive calls.
Sorry for my bad english, thanks for any help!
To add the file Path.txt (with jar3's path) in jar2:
Runtime.getRuntime().exec("jar uf jar2.jar Path.txt");
To read the file in jar2 (Startup is my class name):
String s = "/Path.txt";
is = Startup.class.getResourceAsStream(s);
br = new BufferedReader(new InputStreamReader(is));
while (null != (line = br.readLine())) {
list.add(line);
}
Thank me!
Any built in way to get virtual / relative path or URL from absolute path containing disk name such as?
Or how to convert this :
C:\\ProjectRoot\\Somedir\\demo.text
to this
~/Somedir/demo.text
Thanks.
Request.PhysicalApplicationPath will give you the physical root of your virtual directory.
So in your case if your virtual directory was at c:\projectroot, then you'd want ~/somedir/demo.txt right?
So if you did a string replace on the file path, replacing Request.PhysicalApplicationPath into a tilde character, along with swapping \ for / , then you'd get what you needed.