Running A Class Outside The Directory
Feb 17, 2014
I have a directories in UNIX:
/home/t_bmf/Java/HelloWorld/src/helloworld :will contain a .java file
/home/t_bmf/Java/HelloWorld/bin :will contain all .class file
Let say a have a code:
package helloworld;
public class HelloWorld {
public static void main(String[] arg) {
System.out.println("Hello World");
}
}
a command to compile this even outside the directory /home/t_bmf/Java/HelloWorld/src/helloworld
javac -d /home/t_bmf/Java/HelloWorld/bin /home/t_bmf/Java/HelloWorld/src/helloworld/HelloWorld.java
This will generate a directory /home/t_bmf/Java/HelloWorld/bin/helloworld and file inside this is HelloWorld.class
To run this program I must be in directory /home/t_bmf/Java/HelloWorld/bin and using this command:
java helloworld.HelloWorld
Question:
I already how to run the HelloWorld.class, but I must be in helloworld /home/t_bmf/Java/HelloWorld/bin to run it. Is there's a way to run the class even when I am not in directory /home/t_bmf/Java/HelloWorld/bin? Let's say I'm in /home/t_bmf, can I still run the HelloWorld.class?
View Replies
ADVERTISEMENT
Jul 14, 2014
i want to write a class in such a way that i should get the current execution time of another class which is running. I searched in net but it shows only how to calculate the time duration of the current class which is running. But as per my way, i need the execution time of one class from another class. How to do this ?
View Replies
View Related
Mar 12, 2014
this is the following task i am trying to do. Write an interface Directory to manipulate entries in a telephone directory for the University. The interface must support the following operations:
1) The ability to insert new entries into the directory. Entries should be stored in alphabetical order of surname.
2) Delete entries from the directory either by name or number
3) Provide a lookup method that will find the extension no of a member of staff given
his/her name. You should try to make this method run as efficiently as possible.
4) Change a person's telephone number
5) Print the telephone directory in a neatly tabulated fashion.
Write a class ArrayDirectory that implements this interface using an array to store the telephone directory information. The class must store the surname and initial for each member of staff and their telephone extension (a four digit number which may start with a zero). You may find it useful to define a class Entry to store information about individual entries. The entries should be read into the array from a text file consisting of multiple lines in the following format:
Surname<tab>Initials<tab>Telephone extension
The part that i am stuck on is trying to do the entry method, delete entries method, loop up method, change persons telephone number and be able to print it.
View Replies
View Related
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
May 26, 2014
Consider the url-pattern:
<url-pattern> /Beer/* </url-pattern>
The web app structure is: -
webapps
|
-->AdviceApp
|
-->WEB-INF
--> {{Beer}} This can be real or virtual.
My book says that /Beer/* can be a real or a virtual directory. What is the difference between the two and how do I create a virtual directory in tomcat ?
View Replies
View Related
Apr 23, 2015
I'm having another issue. I have 2 java source files(see below). They are place in the same directory. How do I compile them using classpath?
I have already tried 1st attempt :
javac -cp com.companyname.interview.DuplicateReplace.java DuplicateReplaceTest.java [did not work!]
2nd attempt: javac -cp DuplicateReplace.java DuplicateReplaceTest.java [again, did not work!]
package com.companyname.interview;
public class DuplicateReplace { /* code */}
[Code] ....
View Replies
View Related
Mar 22, 2014
I made a software using Netbeans and javaswing. Accidently i deleted my main file which contains my main class and main method. Just to test, i tried to compile and run and it worked but the style of my buttons and windows has changed. So, what happened? How can i change the style of my programs?
//File Accidently deleted
package time;
public class Time {
public static void main( String[] args ) {
Window wdow = new Window();
wdow.setVisible( true );
}
}
View Replies
View Related
Jun 23, 2014
I am trying to put together an encryption/decryption application that will essentially accept a sentence that is submitted, and spit out the encrypted version and then switch it back to the correct sentence. I have been told to nest my information in the class (rather than the main), but am having difficulty actually understanding how to do this. The error that Eclipse is throwing me is also that it "could not find the main class." Here is my code:
import java.util.Arrays;
import java.util.Random;
public class encryptingWords {
public static void main(String[] args) {
final int ALPHASIZE = 26;
final char[] Lalpha =
[Code] .....
View Replies
View Related
May 19, 2014
This is my program: RemoteXMLRead.java
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.apache.commons.io.filefilter.WildcardFileFilte r;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
[code]....
It is working fine when i run in Eclipse, but is giving error when i run in cmd.. What i need to do to over come this..
View Replies
View Related
Jan 8, 2015
So i have this program that is supposed to execute a command when a button is clicked. I get an error: java.io.IOException: Cannot run program "/Users /brianallison/Documents/Java/RELAP5": error=2, No such file or directory
The actual PATH should be /Users/brianallison/Documents/Java/RELAP5 GUI/issrs/Dist.At least that is where the Java app is and the executable that I am trying to execute when the butotn is clicked. Executable name is relap5.x or relap5.exe depending on the OS.
private void btnRunRelapActionPerformed(java.awt.event.ActionEvent evt) {
String in = " -i " + tfIntdta.getText();
String rst = " - r " + tfRstplt.getText();
String out = " -o " + tfOutdta.getText();
String strip = tfStpdta.getText();
String guistring = "-n gui";
String wd = System.getProperty("user.dir");
String osver = System.getProperty("os.name");
String app = "";
[code].....
View Replies
View Related
Sep 1, 2014
I see you can import in 2 ways:
import java.util.*;
or
import java.util.Scanner/Random/etc;
if I used the first one it imports all the librarys within that (directory?). If so would that add to a bigger file size?
View Replies
View Related
Nov 21, 2014
I am trying to unzip a zip file to a directory but I've tried several different codes and none of them work.The zip structure is like this:
test.zip
New Text Doc.txtNew Folder
New Text Doc.txt
and this is the code I am using
try {
// Open the zip file
ZipFile zipFile = new ZipFile(outputFileName);
Enumeration<?> enu = zipFile.entries();
while (enu.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntry) enu.nextElement();
[code]....
View Replies
View Related
Aug 1, 2007
In my program I have to get directory name&address, in this directory is none, one, or more *.txt(maybe not *.txt files) and I have to read info from all of them.
On C++ is very easy to do that with "findnext, find last, findfirst", so how can I do this in Java?
View Replies
View Related
May 12, 2014
I am working on a java logic game and I want it to be able to work on other people's Mac's, so I tried to figure out how to make it create a folder in which it can create files. The file creating is going fine however the folder never seems to create.Here is the code I attempted to use:
File logicFile = new File("/Library/Application Support/LogicGameSupport");
if(!logicFile.exists()){
if(logicFile.mkdir()){
System.out.println("Directory success");
}else{
System.out.println("Directory failed");
}
}
View Replies
View Related
Apr 30, 2014
Here my code . Iam trying to open text file in window_pane it will open when i click on save it will ask destination to save file if i save example like Read.txt it will save...when i go and check in that folder Read.txt file won't found...what is the error ....
Java Code:
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.*;
import java.net.MalformedURLException;
import java.awt.*;
import java.awt.event.*;
public class Read extends JFrame
[Code] .....
View Replies
View Related
Apr 30, 2014
Here my code am trying to open text file in window_pane it will open when i click on save it will ask destination to save file if i save example like Read.txt it will save...when i go and check in that folder Read.txt file won't found..
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.*;
import java.net.MalformedURLException;
import java.awt.*;
import java.awt.event.*;
[code]....
View Replies
View Related
Oct 5, 2014
Requirements - Use only standard Java API and no apache file utils for this.
Most of the answers I found on the internet either dont meet this requirement or load all file names into an array which can consume too much memory when no. of files = 20,000+. how I can do this. Is there also a way to keep track of new files that were added during the execution of the loop in this code ?
View Replies
View Related
Apr 14, 2014
Im trying to create a linked stack that will hold the starting directory to the current directory, so that when i finish a directory it would go back to the parent. as i go through the files in a directory and find a child directory, i have to stack current directory and process the child directory, when thats done, pop the parent from the stack and continue processing it. Here is my code:
//import io File and ioexception
import java.io.File;
import java.io.IOException;
/*create class that will take a path to a directory, print the name of the argument directory, print the name of each file and directory in argument directory. Prints the directory name and each file and directory inside*/
public class dirStackPrint
[Code] .....
when I run the program, nothing prints, why is that? I'm having trouble understanding the processing of the top, push and pop functions, i have them in my code but they don't seem to be working as they should?
View Replies
View Related
Jan 8, 2015
ensureFileIsVisible not working.
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(currentDirectory));
File f = new File(currentDirectory);
ArrayList<String> names = new ArrayList<>(Arrays.asList(f.list()));
for (String s : names)
if (s.startsWith(yearofIssueTXT.getText())) {
fileChooser.setSelectedFile(new File(s));
fileChooser.ensureFileIsVisible(fileChooser.getSelectedFile());
break;
}
int result = fileChooser.showOpenDialog(addNewCoinBody);
The file is not visible because it is at almost the end of the files in the directory. I want the filechooser to automatically scroll so that the file is seen in the list.
View Replies
View Related
Apr 30, 2015
I've written a program to read files in a directory but I'd like for it to only read the text files of that directory.
import java.io.*;
public class Data {
public static void main(String[] args) throws IOException {
String target_dir = "C:files";
File dir = new File(target_dir);
File[] files = dir.listFiles();
[Code] .....
View Replies
View Related
May 5, 2014
I am trying to crate an interface for the following file (code). The interface that I am trying to create will display a open dialog box where the user chooses which image (.dcm) it would like to open and then it should open it in a frame. The code below shows opening the image. The image opens when the image is in the same folder as the source code but I need it to open from a given path and I am really confused on how to do that. I have tried a lot of methods but still doesn't seem work. How to make it work.
This is the code (assuming the parameter that you are passing in image.dcm, I have tried a full path name on mac computer which is like /Users/Documents/image.dcm, where this path name never works):
/**
* This class displays the first frame of a file from any format
* supported by ImageIO.
* In the case of DICOM files, stored values are displayed as
* is, without using Value of Interest or Presentation LUTs.
*/
class Read1 {
public static void main(String[] s) {
[Code] .....
View Replies
View Related
Sep 30, 2014
I need to design a gui that will find out all the dead symbolic link from the directories. And I used the logic and syntax I find out in java orcle docs. And If I will give the direct path name of the symbolic file then it is running fine with the output and enable to find the smbolic link is active or not. Now the real problem is that , I want that logic of detection should run out through the complete files and subdirectories of the directory. So Then I used the tree walk concept to transver through the complete file system of the directory and embed the logic of the detection inside it for detection of the dead symbolic link. But now it showing erroe which is not approacable for me.
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class To_Transver {
[Code]...
View Replies
View Related
Dec 24, 2013
I'm using Ubuntu. After unpacking the tar file for JSE 1.7 version 45, in the the bin directory for adding an entry to PATH variable, I typed
javac
and I get the message
The program 'javac' can be found in the following packages:
* default-jdk
* ecj
* gcj-4.6-jdk
* gcj-4.7-jdk
* openjdk-7-jdk
* openjdk-6-jdk
Try: sudo apt-get install <selected package>
Do I have to install these ?
View Replies
View Related
Nov 26, 2014
I don't really understand the question is the thing. Its about calling a file in the java program. I read the book and i can see how to call a file from a directory and how to save it and edit it but I don't understand what the instructor is asking for. Mostly what files need called and println.
Assuming the object that manages output will be called writer, write a statement that opens a text file called home.html for output by println statements.
To be file-writable and file-readable, an object must be an instance of a class that implements___________.
Write a statemnt that opens a file for input of objects and assigns a reference to the connection to ObjectIn. Assume the file is in the current directory, with the name automobiles. data.
View Replies
View Related
Jan 25, 2014
My problem is that I want to load an Image from the source directory in Canavas' paint() method.
My code is currently (in a try/catch)
g.drawImage(ImageIO.read(new File(imageLocation)), imageX, imageY, null);
Where imageLocation leads to an image on my HDD ("C:UsersVladdeDocumentsFolders-Filesfolder.png")
View Replies
View Related
Apr 24, 2015
I am trying to understand how package(directory structure) and JAR files work interchangeably. From my understanding JAR is a package file format typically used to aggregate many Java classes. Since many classes are usually contained inside a package, I should be able to create a JAR file from a package, and use them interchangeably. A single JAR file is easier to handle then multiple classes and folders.
To test my understanding of the concept, I am working with the following project structure,
/development_directory
____/BookPackage
________Book.java
____BookDemo.java
Book.java contains the following code,
package BookPackage;
public class Book{
private String bookname;
public Book(String str){
bookname = str;
}
public String getBookName(){
return bookname;
}
}
and BookDemo.java contains the following code,
import BookPackage.Book;
class BookDemo{
public static void main(String ... args){
Book b = new Book("Lord of the Rings");
System.out.println(b.getBookName());
}
}
From the development_directory, I used the following commands to compile and run the project,
development_directory/ javac BookDemo.java
development_directory/ java BookDemo
...and it compiles and works as expected.Now, I will try to convert the BookPackage folder(package) into single jar file for portability, and I am using the following command to do that,development_directory/ jar -cf bookpkg.jar BookPackage ...this command generates the bookpkg.jar file.
I am going to remove the BookPackage folder to see if bookpkg.jar file really works as a replacement for the BookPackage directory structure.
After removal of BookPackage folder, the development_directory structure looks like this,
/development_directory
____bookpkg.jar
____BookDemo.java
Now, I tried to use the following commands to see if the program works as before,
// to compile
development_directory/ javac -cp ./bookpkg.jar BookDemo.java
...it compiles without any error - this means the replacement of bookpkg.jar for BookPackage(package) folder structure is working - Am I correct?
// to run
development_directory/ java -cp ./bookpkg.jar BookDemo
...And I hit an error,
Error: Could not find or load main class BookDemo
But the BookDemo class is at default namespace - why it JRE won't be able to find the main method?
And, the way I am trying to replace package folder structure with a single JAR file - am I getting the concept correctly?
View Replies
View Related