Add Source To Bat File?

Aug 30, 2014

Have the following .bat file that compiles the ReadMindWave.java source with jna and jfreechart. I get a javac error saying 'no source' when the .bat is run, as the .java source needs to be included in the .bat file. Where it goes in the following .bat file?

@echo off
echo Compiling %1 with JNA and JFreeChart...
javac -Xlint:deprecation -cp "C:jna-master*;C:jfreechart-1.0.19libjfreechart-1.0.19.jar;C:jfreechart-1.0.19libjcommon-1.0.23.jar;."%*

The file to compile is in C:MindWaveTestsReadMindWave.java

View Replies


ADVERTISEMENT

Extract File In Same Directory As Source File

Jun 13, 2014

This is a snippet code that im developing. (no source of it) . I am facing a trouble to extract file in the same directory as the source file (example: extract here option)

public class HelperAction {
public static void unzip(String zipFilePath)throws IOException {
File dir = new File(zipFilePath.substring(0,zipFilePath.length()));
// create output directory if it doesn't exist
if(!dir.exists()) dir.mkdirs();
FileInputStream fis;

[Code] ....

View Replies View Related

Copying From One File (source) To Another File (destination)

Jul 5, 2014

I have a file(source.txt) that contains some texts. Now, the java code is to run through each line in the source file and check if that line begins with a number and if true, copy that line to the destination file(destination.txt). I have the code but I am not sure why I can't loop through each line in the source.txt file. Below is my java code:
 
public static void copyFile(File source, File destination) {
BufferedReader br;
try {
FileWriter fw = new FileWriter(destination.getAbsoluteFile());
PrintWriter bw = new PrintWriter(fw);
br = new BufferedReader(new FileReader(source));
String line = new String();

[Code] ....

As shown in the source.txt file, there are 4 lines in the file but when the execution gets to while ((line = br.readLine()) != null) , it executes to false.. Why this is so?

below is the source.txt file

12 is a number
Green is bad
5 is not so cool
you are right

View Replies View Related

Source File Input

Jun 8, 2014

how to add an error message when my program can't find the file the user inputs.

For example:

Enter your source code:
D:Data StructsProjectssrcHelloWorld (I didn't put .java on purpose)
Exception in thread "main" java.io.FileNotFoundException: D:Data StructsProjectsAssignment 3srcHelloWorld (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at HomeworkDriverFour.main(HomeworkDriverFour.java:14)
//Can I get rid of the exception above and replace it with "File not found!"

Enter your source code:This is what I have so far:

import java.io.*;
import java.util.*;
public class HomeworkDriverFour {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub

[code]...

View Replies View Related

Source File Compilation

Jan 22, 2015

when i try to compile following source file, there is a error which states "MovieTestDrive is public, so must be declared in a file MovieTestDrive.java" i didnot understand. i am beginner in java;

class Movie
{
String title;
String genre;
int rating;
void playit()
{
System.out.println("playing the movie");
}
}

public class MovieTestDrive

[code]....

View Replies View Related

Using Enumeration Of One Source-code File In Another?

Mar 30, 2014

To be specific, how can I use enumeration of one source-code file in another.

View Replies View Related

Defining A Class In Source Code File?

Oct 9, 2014

"If you define a public class or an interface in your class, then it should match the name of the java source code file."

Does the statement above mean the following should compile fine ?

public class Animal{
public class Animal{ }
}

The author gives an example saying that if you have a class Multiple.java and in that class, you have:

public class Multiple{}, then it should compile.

But this does not compile. I tried it.

View Replies View Related

Can Access One Class Present In One Source File

Nov 3, 2014

I am having hard time to grasp the concept of java as i am beginner. according to different sources found in internet, only one class is written in one source file. and all those class can be accessed through the main class.
my question is

1.can we access one class present in one source file, through another class present in another source file [not through the class containing main method]?

2.can we create more than 1 class in same source file?is there special way to do it? i do get error always when i try to do so
3.can multiple classes contain main method? or should there be only single class containing it?

View Replies View Related

Source File - Arithmetic Operator Substitution

Nov 6, 2014

My goals:

1) Have some source file be read in

2) Specify what arithmetic operators to swap (+, -, /, *)

2) If an arithmetic operator is read (like a + sign etc) then we swap it with its opposite (- for example)

3) Once the swap is complete, the rest of the file stays the same even if more operators are in the file...it is then output to a file (I am going with 1mutation.java)

4) This is where it gets tricky....it then picks up where it left off to finish reading the + operators (or whatever was specified) and repeats steps 2-3 (but the operator that is already swapped gets left as it was / skipped) and the output is saved as 2mutation.java.

The most I have been able to manage is having it changed 1 operator or all of them at once. I deleted a lot of my work to start fresh / master one operator for the time being. Here is what I have:

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
 
public class OperatorSub {
 
[Code] ....

This is the data file I am using. (see attached) The file should be .java or .cpp but I stuck with .txt for now. How to tackle this? Am I on the right track?

View Replies View Related

Swing/AWT/SWT :: Loading Image File From Source Directory?

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

How Java Finds Jar Contents Imported In A Source File

Feb 10, 2015

how java imports libraries from a jar file inside a source. Let's say I have the following code on Something.java file,

import com.mycomanyA.*;
import com.mycomanyB.*;
public class Something{
public static void main(String ... args){
// code goes here...
}
}

And the Something.java is inside the following structure...

A.jar
com/
mycompanyA/
A.class
Another.class
B.jar
com/
mycompanyB/
B.class
neededImage.gif
bin-folder/
org/
apache/
Something.java

To compile this code(Something.java) from command line I want to use the following command,

javac org/apache/Something.class

And for the compilation to be successful, I'll have to be just above bin-folder because...

- > Only then my default class path will be (.) and java would automatically include A.jar and B.jar(the other way is to add the jar files using -cp argument, which I want to avoid in this scenario)

- > And for the import org.mycompanyX to work I'll have to be in the (.) directory.

Are my assumptions correct about how java find jar contents imported in a source file?

View Replies View Related

Non-Public Class In A Source File Doesn't Matching Its Name

Oct 20, 2014

I have a question about the following snippet concerning the steps the javac compiler follows to compile a program:

[...]at first, searching a class within a package is discussed if the latter doesn't contain a full package name[...]

It is a compile-time error if more than one class is found. (Classes must be unique, so the order of the import statements doesn't matter.)

The compiler goes one step further. It looks at the source files to see if the source is newer than the class file. If so, the source file is recompiled automatically. Recall that you can import only public classes from other packages. A source file can only contain one public class, and the names of the file and the public class must match. Therefore, the compiler can easily locate source files for public classes.

However, you can import nonpublic classes from the current package. These classes may be defined in source files with different names. If you import a class from the current package, the compiler searches all source files of the current package to see which one defines the class. I don't quite understand the red fragment. I wondered if the word "import" nonpublic classes from the current package weren't a synonym for the word "use", since why would we want to import a class from the same package when compiler searches the current package automatically anyway?

However I wanted to test nonpublic classes that are contained in source file which name doesn't match the class name:

NonpublicClass.java:

Java Code:

package com.work.company;
class NonpublicClass
{
public void description() {
System.out.println("Working!");
}
} mh_sh_highlight_all('java');

[Code] ....

Everything's fine when the source file names are the same as above. However, when I change NonpublicClass.java to a different name, there's an error "cannot find symbol" in:

Java Code: NonpublicClass v = new NonpublicClass(); mh_sh_highlight_all('java');

I noticed that the class file for NonpublicClass isn't even generated so that's probably the cause. If I change to the directory of the package the NonpublicClass is contained in and compile it directly, i.e. issue for example:

Java Code: javac NonpublicClass_different_name.java mh_sh_highlight_all('java');

Then a proper class file is generated with the class name, that is NonpublicClass.class, and afterwards I can compile the main program in Start.java.

So the question is what am I missing regarding the cited quote that reads:

If you import a class from the current package, the compiler searches all source files of the current package to see which one defines the class.

? Because adding such an import to CompanyClass.java:

import com.work.company.NonpublicClass;

didn't work either...

View Replies View Related

Java Source Code File Naming With Access Modifiers

Feb 3, 2014

Why is this not valid in java:

Both uses public with the same class/interface name.

Test.java:
public class Test implements Test{
/// Some codes
}
public interface Test {
///Some methods
}

View Replies View Related

Read In Java Source Code File As Command Line Argument

Oct 31, 2014

I am trying to complete this question. I understand the most of it but I haven't go a clue to read in the file name.

Full question: Implement a program that reads in a Java source code file and checks to see if it has balanced {}brackets. Your program should use a stack, implemented as a linked list, to check the brackets.

NOTE: you can use a reference called top which points to the head of the list. Your program should run as a command line program and should take a filename as an argument and print one of BALANCED or NOT BALANCED.

For example: c:> java checkBalanced "myProgram.java" BALANCED

View Replies View Related

Putting Images In GUI / Images In Source File Don't Seem To Be Recognized

Jun 7, 2014

This is my class with the GUI:

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;

[code]....

Eclipse error message:

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at GUI.<init>(GUI.java:26)
at Apples.main(Apples.java:7)

i think the problem is to do with my images not being recognised. I put them in my source in User>...>workspace>src which is correct as far as i know. From what i know the images should show up if i look at my src file in eclipse but they dont. I tried changing the file type from .png to .jpg but it makes no difference.

View Replies View Related

Mvn Repository Go-to Source For Jar Downloads?

Jun 20, 2014

I notice when I look to download library jars, I keep ending up at Maven Repository: Search/Browse/Explore. I wonder is this really the de-facto place to download jars for java libraries? Right now I want to use the apache commons net library in order to build an imap server. And I find myself again mvnrepository:Is this where I should be downloading jar files?

View Replies View Related

ImageIO Unknown Source?

Apr 9, 2015

I am having errors but not sure why.

My two classes. I have pointed out the lines that are causing the errors. -

import gfx.SpriteSheet; 
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;

[Code] .....

View Replies View Related

Javac Not Finding Source Files

Apr 3, 2015

In using javac, I have installed the JDK, set the PATH and JAVA_HOME. When I run this:

"C:Program FilesJavajdk1.8.0_40injavac" -cp C:Gj_javacHTMLCarbonResults.java

I get: javac: no source files

Since I placed the source file path in the command line, I don't understand why it can't find the one .java file.

View Replies View Related

Swing/AWT/SWT :: Where Is Event Source Object

Feb 28, 2015

java.awt.Component is an abstract class, and it's direct Sub-classes are Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, Text Component

So, when I use addXListener(mylistenerclass m);//which is a method of Component class which object is holding the list of all listeners, for a particular Event Source?

I am under the assumption that - there is an Event Source Object(possibly static) for every Event Source type(mouse, keyboard etc) that holds a list of destinations(classes that implements their listener interface) - added to the the object via addXListener method. When an event happens(mouse click, drag etc) the Event Source Object creates an Event Object and send it to all the destinations. Is my assumption correct? I can't seem to find the location or declaration of Event Source Object and the list where it stores it's registered destinations.

View Replies View Related

No Java Source Files In Projects?

Apr 10, 2014

my course material is due for term 1 of my cert 4 programming course, but My lecture will not pass my java projects because there is no source files generated for them in the net beans project structure, tried building, cleaning and building, all i can think of?, tried IDE's 7.4 and 8.0 .

View Replies View Related

Source Code For Pre-defined Methods?

Jul 11, 2014

1.Is there any way by which i can see what is happening inside pre defined methods.

i.e. can i see there source code?

2.Somewhere i learned how to see the content of a pre defined class i.e. by using:

javap java.io.classname

but i dont know what javap means!

View Replies View Related

How To Trace WiFi Near Some Source In JAVA

Sep 9, 2014

I want to trace how many wifi signals are available near some source within some distance in JAVA. How do I do that?

View Replies View Related

Compile Java Source Files At Runtime In JRE

Feb 14, 2014

I am looking for a way to compile Java Source-Files at runtime and save them all in an executable jar; almost like an IDE would do. I know that there is the javax.tools package which provides a JavaCompiler interface and you can use ToolProvider.getSystemJavaCompiler() to get an instance of a compiler. However, this method has one important problem: it only works on machines that have the JDK installed. Not when only the JRE is installed.

I guess at this point that I need some kind of third party library that offers an implementation of a JavaCompiler. Unfortunately, this is really complicated to search for on the internet since all top listings when searching "compile java at runtime jre" do not really provide a solution to the problem.

I am writing a (somewhat) complex simulation software right now which is supposed to be used by people who have absolutely no knowledge of programming. At the same time, this software should provide the user with a certain amount of flexibility and control over the flow of the simulation.

My previous take on this problem was to build a complex system to interprete user settings from a GUI. I would basically read the GUI input, output it to some kind of own scripting syntax which I just quickly made up and have that interpreted at runtime. Then I realized, that is a silly concept and I threw it out before I got far into the developement.
The much better solution I came up with is taking the input from the GUI, create java source code from it and compile it at run-time. Seems much cleaner and nicer to me; will also probably have a better performance, but thats not really an issue anyways.

View Replies View Related

How To Read Input Of Source Code With FileReader

Oct 19, 2014

I'm doing homework and as far as input, my assignment reads: "Your program must take as input the name of a Java source code file such as the source file containing the source code of this assignment." So my question is, how do i do that without linking the directory directly (i.e. C:/users/...)? I'm using FileReader as shown below...

public static void main(String[] args) throws Exception {
FileReader file = new FileReader (WHAT GOES HERE???);
BufferedReader reader = new BufferedReader(file);
String s = "";
String line = reader.readLine();
 
[Code] .....

View Replies View Related

Can A Class Be Broken Into Multiple Source Files?

Apr 3, 2014

The problem is what to do when the source file for a class gets too big ( a judgment call for sure). Is it possible for one class to be defined in multiple files and if so how do you do it, and is it good practice?

I do see ways to refactor into a base class or move code into a helper class but sometimes the abstraction is cleaner as a single class that does a lot of stuff. My problem is how to organize a BIG class?

View Replies View Related

Extracting A String From HTML Source Code?

Apr 8, 2015

I want to extract a specific String from HTML, specifically, I want to extract a String from in between <...>

So far, I've got this

package main;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class HTMLGrabber {
static String allOneString = "";

[code]....

The problem I have is when I change the last parameter in this line:

System.out.println("And the Keywords are:

" +allOneString.substring(allOneString.lastIndexOf("meta name="keywords" content=") + 30, allOneString.indexOf("Fictional History">")+17));

to

System.out.println("And the Keywords are:

" +allOneString.substring(allOneString.lastIndexOf("meta name="keywords" content=") + 30, allOneString.indexOf("">")));

i.e. the generic alternative, I get this error message:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -366
at java.lang.String.substring(Unknown Source)
at main.HTMLGrabber.main(HTMLGrabber.java:45)

Is there a better and simple way to extract a substring?

View Replies View Related







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