Set Path To File In Jar App

May 12, 2014

What I do wrong when I trying to set path to file in my jar app. I have application which work with xml file. I have next project structure:

/project_root_directory
|_  /lib
|_  /resources/file.xml
|_  /src
 
So, I need to set correctly path to my jar file, because when I running it from IDE, it works nice. By default it seems:

private File file;
private StreamResult streamResult;
file = new File("resources/file.xml");
streamResult = new StreamResult(file);

And methods where I can modify the DOM structure via transformer in end of methods:

transformer.transform(source, streamResult);

So, I trying set path to file:

private URL url;
...
file = new File(url.getPath());
streamResult = new StreamResult(file);
 
But it didn't not work, because when I trying to get resource by next condition

url = getClass().getResource("resources/file.xml");
url = getClass().getResource("resources/file.xml");url = getClass().getResource(url = getClass().getResource("resources/file.xml");resources/file.xml");
url - is null
Okay..
 
I tried next solution
 
InputStream input = getClass().getResourceAsStream("resources/file.xml"); 
 
There, I got also null....
 
Also, I tried made absolute path
 
filePath = file.getAbsolutePath();
file = new File(filePath);
streamResult = new StreamResult(file);

But it also didn't work. There I got message seems like: "Can't find resource /User/user1/Desktop/program1/resources/file.xml" - but that's really absolute path to a file.
 
Also, I tried made it via System.getProperty

String filename = "file.xml";
String workingDir = System.getProperty("user.dir");
finalfile = workingDir + File.separator + "resources" + File.separator + filename;
file = new File(finalfile);

I also made unit test which completed with "green light", but in jar its wrong with message "Can't find resource /User/user1/Desktop/program1/resources/file.xm" ....

View Replies


ADVERTISEMENT

Servlets :: How To Upload File To Dropbox With Only File Name (without Path) Using Java

Dec 1, 2014

In my web application i want to upload file to drop-box. I am getting file name from browser.Is it possible to upload file to drop-box with only file name.

Below the drop-box upload code with java.

File inputFile = new File("New Text Document.txt");
System.out.println("inputFile.getAbsoluteFile(): " + inputFile);
FileInputStream inputStream = new FileInputStream(inputFile);
try {
DbxEntry.File uploadedFile = client.uploadFile("/magnum-opus.txt",
DbxWriteMode.add(), inputFile.length(), inputStream);
System.out.println("Uploaded: " + uploadedFile.toString());
} finally {
inputStream.close();
}

In the above code the place New Text Document.txt we have to provide total path of file.

View Replies View Related

File Handling - Display Path Of The File In Text Field

May 6, 2014

I am facing a problem while executing a task. My task is to make such a code which will search for my source code file (abc.java) in all directories and then displays the code in textarea inside frame and along with that i also have to display the path of the file in text field. I have coded something but i am really not getting anywhere near my task.

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.*
 
public class Lab extends JFrame {

[Code] ....

View Replies View Related

How To Find The Current Path Of A File

Jun 24, 2014

First of all, i am using ubuntu and jdk8. My problem: displaying the current path of a file in my system Approach: I have a file called dummy.txt in a given directory which have enough permissions and i did the following:

File file=new File("dummy.txt");
System.out.println(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf("/")));

I expected to see displayed the current path of the file without the name of the file but it is showing a different path. I just want to display the current path of the file without the name.

View Replies View Related

File Not Found - Invalid Path

Apr 8, 2014

Well I fixed my invalid path problem

Now it is telling me that my file is not found and it is exactly where I put it and told JCreator to look for it.

this is what I get:

javac: file not found: C:Program FilesJavajdk1.8.0docsMyName.java

when I go manually to the address, it is there but for some reason Jcreator cannot find it.

View Replies View Related

Image Path Java To Exe / Jar File

Sep 30, 2014

I already done my program with images on it but when i convert it to exe , the images is not appearing.

Usually my images are located at documents netbeansprojectprojectimage.jpg

When i run the code on netbeans the images are appearing but when i convert it to exe or jar file run on a computer without netbeans.. images is not appearing ...

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.ImageIcon;

class Phonebook extends JFrame {
private static final int WIDTH = 430;
private static final int HEIGHT = 200;
public Phonebook()

[Code] ....

View Replies View Related

Drawing Image - Specify File Path

Jul 3, 2014

Gyazo - e5663e8da42ac46a642895d72836b933.png

As you can see I have specified a file path, as it is needed to draw the image.

The image "sun" is in a certain folder inside the directory of my jar file.

But If I were to send the whole package to my teacher to review. The file path would still remain the same, local to my computer making the image, unloadable.?

View Replies View Related

Change File Extension On Path Name In JTextField

Nov 3, 2014

I have a GUI that has three jTextFiled's. The first on gets filled in with a file that I choose and shows the path to that file with the file name

i.e. - c:
s34bil.exe
un estrun.i

I want to change the file extension from .i to .r in one jTextField and then .i to .o in another jTextField.

I am slowly learning Java. I have this coded in VB, but not sure how to do it in java.

Here is the VB script :

Dim thefile As String = txtInput.Text
Dim fn1 As String = My.Computer.FileSystem.GetName(thefile)
Dim fn2 As String = fn1.Replace(".i", "")

[Code] ....

View Replies View Related

JSF :: Upload File With Path Stored In Database?

May 20, 2014

I'm using jsf 2 to upload file, first I upload the file in a system directory, then trying to store the path to database with other information, my stuck is that when submitting I upload the file successfully, find it in the right place, find the other information such as description, file name ... in database but don't find the path. this is my managed bean :

package mbeans;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.List;

[code]...

View Replies View Related

Use Relative Path In Place Of Absolute Path

Nov 7, 2014

I am copying the xml files from one folder to other folder, in the source folder, i have some files which have some content like "backing File="$IDP_ ROOT/metadata/iPAU-SP-metadata.xml" but while writing to the destination folder.i am replacing the "$IDP_ROOT" with my current working directory. The entire copying of files is for deploying into tomcat server. The copying is done only when server starts for the first time.Problem: If i change the folder name from my root path in my machine after i run the server,the entire process will be stopped because the destination folder files already contains the content which is with existed files names or folder names.

So i want to change it to relative path instead absolute path. What is the best way to do it? Please look at code below:

[ // Getting the current working directory
String currentdir = new File(".").getAbsoluteFile().getParent() + File.separator;

if(currentdir.indexOf("ControlPanel")!=-1){
rootPath=currentdir.substring(0, currentdir.indexOf("ControlPanel"));
}else{
rootPath=currentdir;

[code]....

View Replies View Related

How To Write Exact Directory Path To Properties File

Nov 27, 2014

I need to write the exact directory path like C:LisaestUpdate to a properties file.

I am trying it by

FileInputStream in = new FileInputStream(test.properties);
Properties props = new Properties();
props.load(in);
in.close();
 FileOutputStream out = new FileOutputStream(newprop.properties);
props.setProperty("myDirectory","C:Lisa estUpdate" );
props.store(out, null);
out.close();

but the properties file is updated as C:Lisa estUpdate

Extra comes before :.

How can I remove that.

Even I tried it with an command but got same output.

View Replies View Related

FileNotFoundException With Java Scanner With Absolute File Path

Apr 8, 2014

I'm a Java beginner and I've been trying to scan a file using the Java Scanner. I've tried searching online for this error and I only find people's questions who have entered an incorrect relative path. I'm entering in an absolute path and I'm using Eclipse Standard Edition on a 2013 MacBook Pro with Mavericks 10.9.2.

Anyway, the error message I'm receiving on Eclipse is: Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unhandled exception type FileNotFoundException

at App.main(App.java:12)
public class App {
public static void main(String[] args){
String fileName = "/Users/Student/Documents/index.html";

[code]...

Why it cannot find this file. I've checked the absolute file path of index.html on my Mac and I've copied and pasted it into my code.

View Replies View Related

Passing File Path To Servlet Using Drag And Drop Method In Java Web

Jun 18, 2014

currently I am doing my java web application project ,and it has following steps 1) Upload the txt files 2) java servlet gets the txt file's url , read the data and do the calculation 3) pass the results

I almost finished the second step , and working on the first step .Since there are so many input files at a given time , i have to use drag and drop method to get the file's location.how to pass file's path to servlet.( servlet code can read the data from the given txt file path )software used - tomcat and netbeans 8.0

View Replies View Related

JSF :: How To Read CSV File From User Defined Directory Path For Loading To Managed Bean

Jan 10, 2015

I'm using a PrimeFaces UploadedFile xhtml page to select a csv file to read and write using a managed bean (SuperCSVParser.java). The file is read and written to an entity class which then persists the data to a database. The application works fine if I specify a file path on the physical server and select a csv file on that file path. But for the production version I want the user to select ANY file name from ANY directory on their local system.

I know about the FacesContext methods and I've looked at some methods from the java.io File class. Most of these methods are about getting the path from the server, where I want to 'pass' the path String from the client machine to allow the uploaded file to go through. When I try with the below code I get:

java.io.FileNotFoundException: data.csv (The system cannot find the file specified)

I'd like to know what I'm doing as I prefer not to explicitly declare a path in the final app. I'm almost sure that's possible.

<h:form enctype="multipart/form-data">
<p:fileUpload value="#{SuperCsvParser.file}"
mode="simple"
auto="true"

[Code].....

View Replies View Related

Servlets :: Unable To Get Path Of File When Upload Files In Server After Browsing Folders

Jun 30, 2014

I have a code that uploads files in server after browsing folders and files then get the paths of files but I have a problem in getting the paths

List items = upload.parseRequest(request);
Iterator iterator = items.iterator();
while (iterator.hasNext()) {
FileItem item = (FileItem) iterator.next();
if (!item.isFormField())
{ fileName = item.getName();
root = getServletContext().getRealPath("/");
path = new File(root + "/uploads");

[Code]...

list1 must has paths that I want but I do not get the paths of upload files

View Replies View Related

Swing/AWT/SWT :: How To Download File Using Dynamic Download Path Name Using FileChooser

Apr 11, 2015

I have a FileChooser:

JFrame parentFrame = new JFrame();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle(txtPushCode.getText());
int userSelection = fileChooser.showSaveDialog(parentFrame);
if (userSelection == JFileChooser.APPROVE_OPTION) {

[Code] ....

But as you can see, it downloads only to "C:android empcoloricon.png". I want to download it to path where I chose in FileChooser with the name and extension I choose. In short, how can I use dynamic file path names in where ever I want in my applications?

View Replies View Related

How To Set JDK8 As PATH

May 5, 2014

My OS: Windows 7

Problem:

I've tried where javac in command prompt but it can't locate it. I need to know how to set JDK 8 as PATH.

View Replies View Related

Relative Path Not Working

Sep 11, 2014

relative path not working if specified folder is outside eclipse IDE, but if i put same folder in current project it is working.

View Replies View Related

The System Cannot Find The Path Specified

Feb 25, 2015

I have the Java Development Kit downloaded in my C file and my book tells me to compile the program I need to open command windowand change the directory where the program is stored. I tried the command cd to change directory and received this message "The system cannot find the path specified."

I checked the Environment Variables on Windows 7 and the Path says: C:Program Files (x86)Javajre1.8.0_31in

This is after many tries and i still can't change directory and i keep getting the same message.

View Replies View Related

Java Path Variable

Mar 2, 2014

I have BlueJ installed on my computer and it does the job of compiling the java source code written in it. If I want to write and compile source code outside of BlueJ do I still need to download the Java SDK and set the PATH variable, even though I am apparently able to do it in BlueJ?

View Replies View Related

Servlets :: Getting Path Of The Base URL?

Feb 5, 2014

I have a data.json in my J2EE web app.I need to load it either from local path when unit testing or from url when the server starts up.

so I've set it to get the local path by default and what I'm trying to do is that it is is running on a server, I'd like to change the path to a url.

Here is my code:

public String getUrlBase(HttpServletRequest request) {
URL requestUrl;
try {
requestUrl = new URL(request.getRequestURL().toString());
String portString = requestUrl.getPort() == -1 ? "" : ":" + requestUrl.getPort();
return requestUrl.getProtocol() + "://" + requestUrl.getHost() + portString + request.getContextPath() + "/";
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}

which works fine. The only issue is that I had to place this in the login page. Is there a way I can only set the path to the base url upon server start up?

View Replies View Related

System Cannot Find Path Specified

Feb 24, 2015

I have the Java Development Kit downloaded in my C file and my book tells me to compile the program I need to open command windowand change the directory where the program is stored. I tried the command cd to change directory and received this message "The system cannot find the path specified." I checked the Environment Variables on Windows 7 and the Path says: C:Program Files (x86)Javajre1.8.0_31in

This is after many tries and i still can't change directory and i keep getting the same message.The book I am using to learn Java is "Java How to Program: Tenth Edition" from Paul and Harvey Deitel.

View Replies View Related

How To Change Maven Path

Jan 8, 2014

When I write below command:

which mvn

I see below output

/usr/bin/mvn

But it is not the maven installed by me. I think it came with linux

Now I want to change mvn path with following command:

export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
export M2=%M2_HOME%bin

But it does not change. I still see

which mvn

I see below output

/usr/bin/mvn

View Replies View Related

Class Path With Windows 7

May 28, 2010

I've just got a new computer and i tried to set the class path the way i did with windows xp but it's not working. This is what i have done. I added a Path variable to user variables and added C: Program Files (x86)Javajdk1.6.0_20/bin as the variable value. But when i got to command prompt and type javac HelloWorld.java it just tells me javac is not recognised as an internal or external command.

Also another problem is after trying this and it not working i tried to add a path to the system variables. I added a new path variable but i think once i did that it deleted the one that was already there. Is that going to mess up my computer? What the default path variable for windows 7 is?i've got the right destination as i typed cd to change directory and when i typed C: Program Files (x86)Javajdk1.6.0_20/bin it changed to that. And i noticed if i typed in the destination wrong its just made an error.

View Replies View Related

JavaFX Get Coordinates From Path?

May 8, 2014

I'm working on a project right now in JavaFX, and got stuck. I am drawing a path consisting of CubicCurveTo's and I wonder if there's any way to get the X and Y coordinates from certain parts of that path.

Imagine following a curve (path) with a pencil slowly, and every second you take note the X and Y coordinate. I mean I'm not interested in the control points or start and end points, but the points "in between", preferably at a certain interval.

I've searched for many things online, but have trouble knowing exactly which words to search for. "Paths" often bring up file paths, traversing, coordinates etc. all fail to give me any good results.

I tried to be as specific I could, and I don't think my current code is of any interest in this matter.

(The point of it all is that the path should simulate the path a person walks, and I will store the coordinates in a database for every second).

View Replies View Related

JSP :: Cannot Get Correct Path On Refresh

Feb 10, 2014

I want to use the bit of code below to re-write the page to tell the user of a successful registration and then redirect them to another page. My problem is that I can't figure out how to get the path right for the login page. As can see, my first choice was to have the use click to the login page and when I use href it works fine.

I tried to use the entire file page starting at C and that didn't work. I also tried

${pageContext.request.contextPath}/Login

which is what I had to do for the action in the form for the login servlet page.

My question is what is the URL I need to use. By the way, if I jut put in google's URL, or any other for that matter, it works fine.

out.println(docType +
"<html>
" +
"<head><title>" + "Already Registered" + "</title>" +
"<meta http-equiv='refresh' content='3; URL='Login.jsp'></head>

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved