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


ADVERTISEMENT

Set Class Path For One Level Down The Current Directory?

Jun 29, 2014

Can we set the class path for one level down the current directory? My structure is like

binlibresourceshexicon.cmdinside the folder dist.

In this case I could run the .cmd file which has java -cp .;lib;resources client.Test .

c: rycpdist>java hexicon.cmdBut if i put the .cmd file inside bin as like this and run as
c: rycpdistin>java hexicon.cmdI am getting this error Error: Could not find or load main class

Is there any possibility to set the class path in this case

View Replies View Related

How To Create JavaScript To Find Current Month And Current Day Of Month

Mar 17, 2015

I want to be able to use the current date to solve a math problem, specifically as follows:If today is March 17, the math problem of the day should be:

(Month times Day of Month) + 99 = Answer of the Day

(3 x 17) + 99 = 150

How can I create a java script to find the current month and the current day of month, multiple those two together, then add 99 and display the answer as a result.

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

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

Unable To Find JDK Path

Sep 19, 2013

I am new to linux and using centos ver 6.4 64bit . i want to install sqldeveloper so i run below rpms
 
sqldeveloper-3.2.20.09.87-1.noarch.rpm
jdk-7u40-linux-x64.rpm
 
After install  when i run sqldeveloper command then it prompt me for jdk path

1. Which I don't know how to find
2. When I try to give /usr/bin/java1.7.0_09/ and enter then it give me below error
 
/usr/bin/java1.7.0_09
Error: /usr/bin/java1.7.0_09/bin/java not found
Type the full pathname of a J2SE installation (or Ctrl-C to quit), the path will be stored in ~/.sqldeveloper/jdk

View Replies View Related

How To Find Longest Path In A Matrix

Feb 18, 2015

I have some N*M matrix or N*N matrx , and there's a "worm" that can start from any index in the first column, or, any index in the first row. i need to choose the longest worm that satisfying this :

The index that comes after the index before him must be greater then 1. and i must use recursion, also for helper methods. no loops at all. that's it. i'm having a problem to find the longest worm in the matrix.

My idea was to create an helper array and assign to the array indexes a variable that will count the steps of the worm and finally assigns in to the helper array index. then i used findMax method to find the max value in an index. and thats will be the longest worm. i wrote a lot of code so i wont put it here. i will say that i'm close. if the longest worm is 6 i get in my output 7.

View Replies View Related

Simple Agent Find Path?

Feb 13, 2015

i want to build a simple x,y grid in eclipse. Where an simple agent can search for a goal and end the episode.

I have java experience but I cant get my head around something simple as this.

I know there will be state, actions and environment and agent class.

But I cannt figure out where to start with this, do i start with state or action.

View Replies View Related

Trying To Find Cheapest Path Recursively

May 25, 2015

Trying to find cheapest path recursively, given a grid a integers trying to recursively find the cheapest path from the top to the bottom. cheapest being the sum of the path. I think I've made my code over complicated. recursive things are usually much more elegant

import java.io.FileInputStream; 
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException; 
public class trial {
public void readFile(String fileName)
 
[Code] ....

and here is the grid

27 19 18 85 32 11 18 24 22 98
60 83 52 61 18 64 74 33 95 42
56 27 71 56 65 70 18 78 35 74
15 89 19 92 61 76 92 42 57 26
88 28 78 45 21 98 11 72 82 97
49 54 88 79 16 43 27 78 52 71
17 18 60 40 72 39 70 52 96 11 
62 79 25 50 73 40 98 64 44 72
25 79 72 25 64 35 29 16 77 96 
12 93 49 64 61 34 83 87 34 36

View Replies View Related

How To Find A Path Through Array Maze

Mar 4, 2015

So what I'm trying to do is write a code in java which finds a path through a maze. I want it to go through the maze and determine if there's a * symbol at that location or not. If there is a * symbol at the specified location then the program would search for another position until it finds one without the * symbol and if it can't then I'll have the program return null. I also want it to implement backtracking which I'm not sure how to do. Here's my code so far

private boolean findPath(int fromRow, int fromCol, int toRow, int toCol){
boolean solved = true;
for(int i=fromRow; i<toRow; i++){
for(int j=fromCol; j<toCol; j++){
if (x[i][j] == ('*')){
//do something
}
}
}
return false;
}

the code isn't finished yet however what I'm not sure is what do I do with the if statement and how do I implement backtracking?

View Replies View Related

Array Is A Set Of Numbers In Triangle - Find Maximum Path

Aug 12, 2014

If you aren't familiar with the euler problem 67, you are given an array that is a set of numbers in a triangle. Like this

3
7 4
2 4 6
8 5 9 3

and you have to find the maximum path, which for this one is

(3)
(7) 4
2 (4) 6
8 5 (9) 3

I have solved this problem iteratively with the code below

depth = depth-2;
while (depth >=0) {
for (int j = 0; j <= depth; j++) {
values[depth][j] += Math.max(values[depth+1][j], values[depth+1][j+1]);
}
depth -= 1;
}

depth is a variable for the row in the triangle. My problem is that i need the solution to be recursive and i am having trouble doing this. So far i have

public static int findMax(int[][] array,int depth) {
if (depth==0)
return array[0][0];
else if
}

View Replies View Related

Assign Current Null Value To Current Date?

Mar 6, 2014

How can i assign current  null value to current date, I only what to assign this if the current value coming from database is null otherwise i must use value from database

public static String getDate(Calendar cal){
        return "" + cal.get(Calendar.DATE) +"/" +
                (cal.get(Calendar.MONTH)+1) + "/" + cal.get(Calendar.YEAR);
    }
try {

[Code] .....

View Replies View Related

Writing Current Time To Text File

May 29, 2014

I'm working on a project for class that asks me to record punch-in and punch-out times for employees. However, I am having difficulty figuring out where I am going wrong as none of the information will write to the text file in the ArrayList that I have created. The code is as follows:

import java.text.*;
import java.util.*;
import java.io.*;
import java.nio.file.*;
public class TimeClockApp {
// declare class variables
private static EmployeeDAO employeeDAO = null;

[Code] .....

I want to keep the coding as simple as possible as I am new to Java, and have spent hours upon hours trying to figure this all out. The console output looks like this:

Welcome to the Punch-In/Punch-Out Screen

Please choose an option below:

I. Punch In
O. Punch Out
Choice: i

PUNCH IN
--------
Enter Employee ID:
8
8Punch-In Date & Time: 2014/05/28 22:44:26
[]
Press enter to return to the main screen:

View Replies View Related

Measure Current Download Speed Of File?

Jan 5, 2014

Is there a way to measure current download speed of a file being downloaded? I've searched all over google and the only thing i get is average download speed. This is basically how it is being done, the result is average download speed.

Java Code:

OutputStream out = null;
URLConnection conn;
InputStream in = null;
long startup = System.currentTimeMillis();
try {
URL url = new URL(adress);
out = new BufferedOutputStream(

[Code] .....

View Replies View Related

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

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 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







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