Loading File From Input
Mar 24, 2015
how I can change my code so that somebody can actually input the specified file path, rather than having it fixed in the code. I previously used
Scanner in = new Scanner(System.in);
System.out.println("What is the filename?");
String input = in.nextLine();
File file = new File(input);
But then the program would not display the frequencies.
import java.io.File;
import java.util.*;
/*
This program will allow the user to enter in a text file name, when prompted the program will anaylser the text and display the frequencies
*/
public class AssP {
public static void main(String[] args ) {
Scanner scan;
try {
Scanner scanner = scan = new Scanner(new File("C:/Users/Mary/workspace/Assingment/src/test.txt"));
[code]....
This is my current code and I need to so the user can load their own files.
View Replies
ADVERTISEMENT
Oct 22, 2014
We have a custom authorization in our application login page, authorization by using eToken and java (signed jar classes) and applet as login button on page. It's work fine on older and current java versions like 7u67, 7u71 but it's not work on new java version 8u25.
We write a test class named AuthControl without package, we found that problem is in .jar file path, for example:
&APPLET_VERSION. is a jar file name, uploaded using "Shared Components / Static Files - Create"
<script src="https://www.java.com/js/deployJava.js"></script>
<script>
var attributes = {code:'AuthControl',
archive:'#WORKSPACE_IMAGES#&APPLET_VERSION.', width:132, height:37}; // problem in the path to the .jar file
var parameters = { scriptable:true, mode:'login' };
var version = '1.6';
deployJava.runApplet(attributes, parameters, version);
</script>
Error is:
...
java.lang.ClassNotFoundException: AuthControl
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
basic: load: class AuthControl not found.
...
But if we use a direct path to the jar file, it's work fine without errors, example:
<script src="https://www.java.com/js/deployJava.js"></script>
<script>
var attributes = {code:'AuthControl',
archive:'http://example.com/myapplet.jar', width:132, height:37};
var parameters = { scriptable:true, mode:'login' };
var version = '1.6';
deployJava.runApplet(attributes, parameters, version);
</script>
Why this is happens on 8 java version?
View Replies
View Related
Oct 2, 2014
I am not sure why I am getting this error. The code is not finished at all, but I am stumped on how to get past loading in the things from the text file. Here is my code:
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class Hurricanes2
{
public static void main(String[] args)throws IOException
{
//declare and initialize variables
[code]...
It compiles fine, but when I execute it I get this.
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
Nov 7, 2014
The game doesn't seem to be working but you can win by loading a winning saved game.
Hint: Remember that all numbers have a unique set of Prime Factors.
I have been struggling to solve this. The code is not in error. I am trying to load a winning file but unable to solve.
Here is the java code:
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;
public class Main {
static final int GAME_SIZE = 40; //Disk sizes go from 0->39
// Produce a list of the first N prime numbers
[Code] ....
Results:
C:UsersSal_2>java Main
Welcome to Towers of Toast!!!
Type 'new' to start a new random puzzle
Type 'load' to load a saved puzzle
new
[0, 2, 3, 4, 5, 6, 8, 10, 14, 19, 20, 25, 26, 28, 35, 38, 39]
[7, 9, 11, 13, 15, 21, 22, 23, 27, 31, 32]
[1, 12, 16, 17, 18, 24, 29, 30, 33, 34, 36, 37]
|
|
XX |
|
XXX |
|
XXXX |
|
XXXXX |
|
XXXXXX |
X
XXXXXXXX XXXXXXX
XXXXXXXXXXXX
XXXXXXXXXX XXXXXXXXX
XXXXXXXXXXXXXXXX
XXXXXXXXXXXXXX XXXXXXXXXXX
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The game is broken! We saved your game, though. Here are your save game numbers:
146209709250387100944095470
52067710192022655041
21882855117530023387473
C:UsersSal_2>java Main
Welcome to Towers of Toast!!!
Type 'new' to start a new random puzzle
Type 'load' to load a saved puzzle
load
Enter save number for pole 1:
3
Enter save number for pole 2:
1
Enter save number for pole 3:
11
Exception in thread "main" java.lang.RuntimeException: Not all disks accounted f
or
at Main.main(Main.java:100)
C:UsersSal_2>
View Replies
View Related
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
Jul 14, 2014
So I was going to try to create a program that prompts input and creates a file (That didn't exist before) with that input as name.Then, the program prompts inputs after stating questions such as 1 + 1, then if the user inputs an answer, put "Question # = Correct "or" Wrong.Code SO Far:
Java Code:
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
public class File_Read {
public File_Read() {//File_Read is the Interactive object
[code]....
So that it puts the Correct or Wrong into the file.
View Replies
View Related
Sep 24, 2014
Well my code is supposed to ask for an input file and then (ex: input.txt), read the input file and create an output.txt file with the anagram for the words in the file. Also it should be displayed on the screen. However my code doesn't display the anagram on screen or the output file!
Heres is the code:
import java.io.*;
import java.lang.*;
import java.util.*;
/* This program will read a file given by the user, read the words within the file and determine anagrams of the given words. If the file that the user inputs is empty, then the program will output "The input file is empty."
* The program will read the file line by line, counting the total number of words read. If there are more than 50 words, "There are more than 50 words."
* will be printed, and the program will terminate. After each line is read, the words in the line will be separated,punctuation characters will be removed, and upper case characters will be switched to lower case.
* If any word is larger than 12 characters, that word will not be considered in the total amount of words in the file and it will not be sorted.
* After each word is read, the letters will be sorted and stored into an array containing each
* word's 'signature'. After all the words have been read, words will be printed to the output file on the same line based upon their signature.
*/
public class Anagram {
//Creating constants for maximum words in file and maximum chars in word
public static final int MAX_CHARS = 12;
public static final int MAX_WORDS = 50;
[Code] ....
View Replies
View Related
Mar 21, 2015
I am trying to read a file and input each line of the file into an array. I have not set the array size as I was hoping to fill the array using a while loop. Unfortunately the scope of the array does to work inside the while loop so I am being told that the array 'students' has not been initialised even though it has just outside of the while loop. Is it possible to do what I am trying to without having the array initialised in the while loop as surely the array will be reset every time if it was in the while loop? Here is my code:
public static void students(String file) throws FileNotFoundException {
try {
File studentInfo = new File(file);
Scanner input = new Scanner(studentInfo);
String[] students;
[Code] ....
View Replies
View Related
Mar 22, 2014
So my assignment is to read these values from an input file which I previously created. The 10 values represent miles traveled and I convert them using some formula my prof gave me to get the total cost, and output both values to an output file.
My programming question is the first number on the input file isnt a mileage value its the number 10, which is the number of values to be processed, which we're supposed to use in order to control a for or while loop which we'll use to process the contents of the input file. How would I create a while or for loop and get it to skip the first value of the input file?
We're not allowed to use arrays for this assignment.
Also here's my code so far, and it says its not being able to find the file, I made sure the file name is exactly as saved, and its saved in the same directory as the java class that i created for this assignment so I don't see what the problem could be?
Here's my the class with the main method
import java.util.*;
import java.io.*;
public class QudratullahMommandi_3_07 {
public static void main (String[]args)
[Code] ....
This is the error message I get
----jGRASP exec: javac -g QudratullahMommandi_3_07.java
QudratullahMommandi_3_07.java:17: error: unreported exception FileNotFoundException; must be caught or declared to be thrown
Scanner input = new Scanner(inputSource);
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
View Replies
View Related
Apr 28, 2014
This is my input from my text file: 1|John Jay Smith|1985-01-10|2010-05-10|2014-03-05|212-222-2233..So, I have to convert 1 to integer. Break John Smith into first name as John and Middle name as Jay Last name as Smith.If no middle name is given then first is John and Last is Smith . Read 1985-01-10 as a date value . 2010-05-10 as another date value which could be null. 2014-03-05 as another date value which could be null. and at last 212-222-2233 as phone number.
Scanner sc = new Scanner (inFile);
sc.nextLine();
while (sc.hasNext()){
String row= sc.nextLine();
I want to read this line of input and assign the value accordingly.
View Replies
View Related
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
Oct 25, 2014
The program is reading from file input. how can I replace hate with love the file contains only one line.I hate programing!
Java Code:
[import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Program3 {
public static void main(String[] args) {
Scanner fileIn = null;
[code]...
View Replies
View Related
Nov 15, 2011
I usually code in PHP, C++ and ActionScript.I'm trying to follow an example of how to add images to a full screen application. What he does is that he adds a JPG background image, and then 4 PNG images. I tried to do it like I always do, by writing the code by myself looking at the book. It didn't work. I searched for errors in the code, changed some things, tried different things, but it didn't work. Then I tried to use his own code, that I downloaded from his website. That didn't work either.. I tried to find another way to add an image, and I can't seem to figure out a way to implement images in any other way into this class that's written in this book.. My Java programming level isn't just high enough.
Here's the code for the file where the images load, downloaded from the authors website (I've modified the brackets and some spaces so that it becomes easier to read):
Java Code:
import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class ImageTest extends JFrame {
public static void main(String[] args) {
DisplayMode displayMode;
[code]....
View Replies
View Related
Oct 12, 2014
Is there anyway to format my input file "IF1.txt" into an excel/csv file, but with the content rearranged into a desired format? (all of this has to be done by a java program)
Here is the input file IFT.txt:
R1 : Integer,3 Food
R2 : Integer,3 ID
R3 : Integer,3 Temp
R4 : Integer,3 Weight
R5 : Integer,3 Age
R6 : Integer,3 Length
[code]...
Desired Output:
TIME Food ID Temp Weight Age Length
00:00:00.001 1 0 0 0 0 0
00:00:00.002 2 0 0 0 0 0
View Replies
View Related
Mar 26, 2014
I'm having some kind of weird problem reading input from a file. It says that my scanner object I'm using to hold an item of information isn't initialized, when I do try to initialize it, it says error variable already initialized. I'm using the scanner to read input from a file whose contents are this
10
150.4
88.4
-3.14
499.4
799.4
1299.8
0
1900.2
901.7
4444.4
This is my program
import java.util.*;
import java.io.*;
public class QudratullahMommandi_3_07 {
Toolkit_General toolKit = new Toolkit_General();
public static void main (String[]args)throws IOException
[Code] .....
This is the error message
QudratullahMommandi_3_07.java:34: error: variable holder2 might not have been initialized
String holder2 = holder2.trim();
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
View Replies
View Related
Oct 30, 2014
i dont know how to write main that would open the input file and read using this method...
[/package AssignmentSeven;
import java.io.*;
import java.util.Scanner;
public class Assignment7
{
public static void Towers(int nTowers, int fromTower1, int workTower2, int toTower3) {
if(nTowers == 1)
[code].....
View Replies
View Related
May 1, 2015
The following program should read in a file on my desktop (I have the path set in Netbeans to that location) and produce a Histogram. Instead I am receiving this error.
Exception in thread "main" javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1301)
at Histogram.main(Histogram.java:9)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Here is the code for the Histogram:
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class Histogram {
public static void main(String[] args) throws Exception {
int[][][] ch = new int[4][4][4];
[code]...
Why it's not reading the file?
View Replies
View Related
Sep 28, 2014
this is my code...in my code i cant give input form my console...it takes input but it doesn't save in a target file..My code is :-
package filetester;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
[code]....
View Replies
View Related
Mar 19, 2014
I have opened up an input file using
File input=new File("hello.txt")..
Then I have created a scanner object that reads data from the file.
Scanner read_file=new Scanner (input).
my question is when closing the files why can't I just do input.close() since that is also closing the file?
View Replies
View Related
Feb 11, 2014
I have to show a loading image which should tell some proper loading message in jsp.
View Replies
View Related
Jun 20, 2014
I have added the image in the src and bin directories and cross-checked that the name of the image file is correct..Here is the main class
import javax.swing.*;
public class apples
{
public static void main(String args[])
{
JFrame frame = new JFrame();
MyDrawPanel wid = new MyDrawPanel();
frame.add(wid);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(300,300);
}
}
and here is the class that does the image adding part
import java.awt.*;
import javax.swing.*;
public class MyDrawPanel extends JPanel
{
public void paintComponent(Graphics g)
{
Image image = new ImageIcon("b.png").getImage();
g.drawImage(image,20, 20, this);
}
}
View Replies
View Related
Sep 18, 2014
So I would like to get information out of a web-API. But my question is how I do this. I guess I need to read the URL first. And parse it after but what is the best way?
For example : [URL] .....
View Replies
View Related
Jan 31, 2014
We are using an applet in our web application. The applet of our application is dependent on bouncycastle jar,bcprov-jdk15.jar and few other jar's whose size comes around 4 mb. When using the appliaction on jre7, the applet is taking too long time to load than usual time. Is there any way to place these jar's in client machine? Will it improve the performance? Is there any other way to reduce the loading time of applet apart from placing jars in client machine?
View Replies
View Related
Jun 6, 2014
I'm attempting to compare user input to a text file that I have set up whenever the user types in an employee ID number. I want to be able to tell the user that either the ID number is valid, or that it is not valid and must be re-entered by comparing it to the employee.txt file, and then record the valid ID number to the timeclock.txt file. I'm recording the next available employee ID number instead of the one I typed in. The output of the program looks like this: i82014/06/06 12:16:56 (I typed 1 as the employee ID.)
import java.text.*;
import java.util.*;
import java.io.*;
import java.nio.file.*;
public class TimeClockApp {
// declare class variables
private static EmployeeDAO employeeDAO = null;
private static Scanner sc = null;
[code]....
View Replies
View Related
Oct 14, 2014
So this is probably pretty simple but I can't seem to figure it out. My teacher wants us to write a code that scans a text file, then outputs some text based information AND displays an applet bar graph of the data sorta like this for the text:
Sample Bar Graph
1-10 |*****
11-20 |******
21-30 |**
31-40 |*
41-50 |***********
51-60 |******
61-70 |********
71-80 |***
81-90 |****
91-100 |****
and then an applet thats the same info just a little more graphic. My code interprets the input well, but when i try to make an applet output, the code basically forgets all of my variables and starts anew (when i just state the public static graphic (paint) class after everything) OR it refuses to scan the input file (if i switch the public class from main.....throw ExceptionIO to just public class graphic(paint))
Also, as a side note, any way to have java automatically determine how many separate lines there are in a text file without me having to manually count them.
import java.util.Scanner;
import javax.swing.JApplet;
import java.awt.*;
import java.io.*;
public class Project2 extends JApplet {
[Code] ....
View Replies
View Related