Check Specific Value From A Specific Line From TXT File

Feb 8, 2015

I have some problem to understand the way to make this:

In my main class a user can save his name in a txt file (and the system initially will add 6 value equals to 0) than he can choose between 6 level and make it.

example of .txt file data:

mario 0 0 0 0 0 0
carl 0 0 0 0 0 0

AT THIS MOMENT i just made other class and they work, is this new one that is hard for me. I'm trying to make a class that:

1- (first method called verificaRisultati) take name_used and level_choosed from the main and go to check in the .txt file if that level before was done right(1) or wrong(0)

and return something like "before you made this level properly" or "before you made this level incorrectly" AND THEN let the user start with the level.

2- (second method called salvaRisultati) at the end of the level i wanna pass the result (correct/incorrect) to another method of this class that will save the value (1 or 0) associated to the user in the right position.

This is the class that i'm writing:

Java Code:

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
public class ResultUsers {

[Code] ....

I really need some hint and some code example because I'm stuck. How I can take exactly the line with the user name? How I can correctly split the line in an array and then read/modify the value for that level?

View Replies


ADVERTISEMENT

Changing Value In Specific Point Of Specific Line In TXT File

Feb 9, 2015

So here we go with my problem:

- from the main class will arrive three variable (String name_used, int level_choose, int level_result)

I have a .txt file with this kind of formatting:

mario 1 1 0 1 0 1
carlo 0 0 0 1 1 0
...

Where I use 1 and 0 in the main for write if the level (you see that the numbers are always sixr? are egual to six level existing) BEFORE is done correct or wrong

- when in the main a user make a level a feedback coming back from the class level saying if the user made the count correctly or wrong. and i wanna replace the value (1 or 0) in the txt file with the new level result.

So i have all what i need as parameters i think.

name_used to look for the correct line in .txt file with .indexOf
level_choosed to go throught the correct index of that line
level_result (1 or 2) to be replaced with the existing one

Java Code:

public void salvaRisultati(String name_used, int level_choosed, int result_of_level) throws FileNotFoundException{
}
} mh_sh_highlight_all('java');

View Replies View Related

Is There A Way To Append Text To A File On A Specific Line Or Location

Jan 21, 2015

I know how to append text to a File using the true argument but I would like to be able to append to a certain line In the file.Basically I've made a simple html page with Image links to different sites. I'm trying to make an app that will take a new site as Input and append It to the html file before the </body> tags.

View Replies View Related

File Handling In Java - Modifying Specific Line

Mar 12, 2015

How to modify a specific line of a file in java. File name must be accepted from command line.

View Replies View Related

Removing Specific Line From Text File That Contains Certain String?

Mar 8, 2014

So basically, if a line in a text file contains a certain string, that specific line will be deleted. It should probably be similair to this method?

Java Code:

/**
* Replace text.
* @param replace
* The text to replace.
* @param replaceWith
* The text to replace with.
*/
public static void replaceSelected(String replace, String replaceWith) {
try {
BufferedReader file = new BufferedReader(new FileReader("data/replacer.txt"));

[code]....

View Replies View Related

Searching TXT File For A Specific Keyword And Output Whole Line

Feb 12, 2014

I need to search a txt file for a specific keyword and then output all the lines that contain that keyword. Right now I I think I have my search done but I don't know how I would print the whole line.

TextIO.readFile("xxx.txt");
String search;
String word;
int count=0;
TextIO.put("Please enter your search word: ");
search = TextIO.getln();
while (!TextIO.eof()) {
word = TextIO.getln();
count = count+1;
if (search.equalsIgnoreCase(word)==true){
TextIO.put(count + "-");
TextIO.put(word);

Right now it doesnt even let me enter in any values for the search. Not sure what I've done wrong..

View Replies View Related

Read Lines With Specific Characteristics From A File / Exclude All Others Line?

Jan 16, 2014

I am trying to write method to read lines with some specification from a file. for Example,

my text file contains following:--

12-01-0113:26San Jose12.99DVD
12-12-3009:40Miami13.50Music
14-08-3010:20Arizona16.03Scientist
11-07-1009:10New York25.00ColdPlay
14-08-3010:20Arizona18.04MeetYou
14-08-3010:20Arizona50.03Scientist
11-07-1009:30New York25.00ColdPlay
11-07-1009:20New York25.00ColdPlay

tab separated values, for different columns and these are the lines only I want method to read.Now suppose if any is there as below, or even enter

12-01-0113:26San Jose12.99DVD
12-12-3009:40Miami13.50Music
14-08-3010:20Arizona16.03Scientist
11-07-1009:10New York25.00ColdPlay
14-08-3010:20Arizona18.04MeetYou
[new lines]
14-08-3010:20Arizona50.03Scientist
11-07-1009:30New York25.00ColdPlay
//This line should not be read
even this should not be read #$%^&
11-07-1009:20New York25.00ColdPlay

That particular line should be escaped. Till now I have done when the file format is proper, and it is as below:--
 
public static void main(String[] args) {
BufferedReader br = null;
String temp = null;
List<String> arrayRead = new ArrayList<String>();
try{
br = new BufferedReader(new FileReader("D: estingSalesData.txt"));

[code]....

View Replies View Related

Write A Specific Byte Sequence To A Specific Memory Location On A Removable Storage Drive?

Jan 29, 2014

I am trying to write a specific byte sequence to a specific memory location on a removable storage drive. Does Java allow me a way to do this? I know the dangers in accessing memory, but the memory location of the data that will be written will never change.

how to assign a variable a memory location.

View Replies View Related

Swing/AWT/SWT :: Move Focus From Specific Jcombobox To Specific Jtextarea?

Nov 5, 2014

How do I move focus from a jcombobox to a specific component say a jtextarea.

My attempt below seems to be moving to a random component not the desired jtextarea.

takenByCombo.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_TAB ) {
e.consume();
dayJTArea.requestFocus(); // focust not moving dayJTArea
}
}
});

I applied the above logic to move focus from a specific jtextarea to another jtextarea as seen below and it works as desired.

dayJTArea.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_TAB ) {
e.consume();
monthJTArea.requestFocus();
}
}
});

View Replies View Related

Check If A Sentence From User Has Specific Letter?

May 1, 2014

I am trying to write a simple program that checks if a user's input has a specific letter using the ".contains" method but its not doing what i wanted to do. here is my code below.

import java.util.Scanner;
public class secret
{
public static void main(String args[]) {
Scanner sc;
char hidden='a';
String guess;

[Code] ....

View Replies View Related

String Analyze - Take A Sentence And Check How Many Times Specific Words Come Up

Sep 8, 2014

Basically the requirements are to take a sentence (string of text) and check to see how many times specific words come up and then add to the counter depending on the word.

But I can not seem to get it to add the instances of the goodwords and badwords.

package Strings;
import java.io.*;
public class SentimentAnalyser {
private static String analyse(String text) {
int pw = 0;
int nw = 0;
String[] searchword = { "bad", "terrible", "good", "awesome" };

[Code] ....

View Replies View Related

Read / Write From Specific Line

Mar 17, 2014

I have a question for the read and write method in file.In my code for writing i m using PrintWriter and for reading Scanner.So i m saving data to file and when is need it i m reading from the file.but i also have to delete specific data from it.Is there a way to delete a specific line from the file?When i google my problem i found that is better to save your data to temporary file and then to the final.

View Replies View Related

Print A Blank Line After Certain Specific Points In Iterator

Feb 17, 2015

I have the following HashMap:

// 2009
nobelPrizeWinners.put("2009 Physics",
new PrizeWinner[] {new PrizeWinner("Charles K.", "Kao"),
new PrizeWinner("Willard S.", "Boyle"), new PrizeWinner("George S.", "Smith")});
nobelPrizeWinners.put("2009 Chemistry",
new PrizeWinner[] {new PrizeWinner("Venkatraman", "Ramakrishnan"),

[Code] .....

At the moment, my output is:

2008: Chemistry: Osamu Shimomura, Martin Chalfie, Roger Y. Tsien
2008: Economics: Paul Krugman
2008: Literature: Jean-Marie Gustave Le Clézio
2008: Medicine: Harald zur Hausen, Françoise Barré-Sinoussi, Luc Montagnier
2008: Peace: Martti Ahtisaari

[Code] .....

However, I need a blank line between the final entry of 2008 and the first entry of 2009.

View Replies View Related

Possible To Check If Classes Contains A Specific Method And Then Run That Method?

Oct 5, 2014

I'm working on a simple 2D Game Framework. Currently it's creating a window, but I'm working on an update method.

I constantly export the framework as a .jar file, and I've added it to the game's build path (using eclipse). I wonder if I can check all classes in the game-project (the project in which I've refecrenced the Framework in) for a specific method (for example update()) and call all found methods with that name from the framework's main class, like this:

public class FrameworkClass1 {
  private void checkForUpdateMethods() {
// Check for update methods on program start
} public void update() {
runAllFoundUpdateMethods(); // Run all update methods found in the scan
}
}

I want to do this because it would be a simple way to update and render the game. If the main game-class look something like this:

public class Game {
public void update() {
// Update the game every time this is ran
}
}

it will be automatically updated, because it contains a method named update(), instead of naming the main game-class with a specific name etc. It will simply be more flexible that way!

View Replies View Related

I/O / Streams :: Get Specific Value From Txt File

Sep 22, 2014

I know that it's possible to retrieve a line from a txt file but say for example my file looked like this:

staff id = 1
firstname
surname
age

staff id =2
firstname Kate
surname Hollar
age 33

staff id =3
firstname Daniel
surname Hong
age 21

It is possible to retrieve just the staff id's?

View Replies View Related

JSP :: Download Uploaded File In Specific Folder?

Mar 7, 2014

I have uploaded file into specified folder.So I have to download it..

View Replies View Related

Change Specific Lines In Text Inputted From A File

Nov 29, 2014

I can't seem to understand how to change certain line of text, inputted from a file. For this I really don't know where to begin. I have got the input from the file. But I want to change like very other line in the file. Can't seem to understand how this could be done. Is there away to access specific lines from the file and edit them? So far, i have this:

import java.util.*;
import java.io.*;
public class ChangeEveryOtherLine {
public static void main(String[] args){
//Constructing file object representing input file
File inputFile = new File("input.txt");

[Code] .....

View Replies View Related

Processing Text File Into Specific Format In Java

Mar 30, 2014

I have text file of this form:

0file:/home/lenovo/mallet/cleantweet/242874110.240622335890878130.1593492469451548700.130861040068201270.1129582267689684590.0868854788292128480.
0807757885763000940.078431372549019660.0604575163398692850.02926967888604717320.020389315146348393
1file:/home/lenovo/mallet/cleantweet

[Code] ....

Am i going in correct way?

View Replies View Related

Read Text File And Perform Operation On Specific Columns

Dec 9, 2011

I am somewhat of a java newbie (learned it awhile back and just getting back to programming some again.) I have a text file of data much larger than this, but here are the first ten rows and first 10 columns.

39755320111041730140.633038085-2.117082366149.069997
39850320111041730150.633038085-2.117082511148.309997
39955320111041730160.633037998-2.117082293149.509997
40055320111041730170.633037945-2.117082351149.239997
.......

I can read and write all the data back out to files. But I am not sure about a few things.

First would it be best to use BufferedReader and OutputStream such as:

public static void main(String[] args) throws IOException {
BufferedReader bReader = new BufferedReader(new FileReader ("testdata.txt"));
BufferedOutputStream bytesOut = new BufferedOutputStream(new FileOutputStream ("outfile.txt"));

Second, I was then going to initialize an array but I might have 30 or more columns of data, of which I might perform and output only 10 columns to my output.txt file so is this a good way?

Third, I only want to perform operations (such as average the data, convert units or multiply two columns together) on 10 of the 30 plus columns and print out results to output.txt file. For example, In testdata.txt file above, I want to skip first seven columns. I then want to take column 8 and multiply by 100 then divide by 3 and output result to output file. I want to do same for column 9. Column 10 I want to multiply by different number (by 3.5).

View Replies View Related

Get List / Map Or Array Of A Specific File Type Files In A Directory?

Sep 18, 2014

If I specify the directory in file type or path string type how can I get a list of files that are file type .yml in that folder, so I can loop through and do something with each single file.yml in that specified directory.

View Replies View Related

Create A Java Program That Can Read Specific Data Within Csv File To Work Out Averages

Aug 7, 2014

i am fairly new to java but have made a few projects so i do know most aspects that would allow me to complete the task its just i have been stuck at the same place now for 2 days.The project is to create a java program that can read specific data within a csv file to work out the averages etc. The csv file is a database of different weather stats . an example of the first 12 months of the csv file is below..

[CSV FILE]

year ,month,average rainfall etc

1946 15.70.616108.131.5
1946 28.23.56111.871
1946 38.82932.9 102.9
1946 414.16.3029.2 150.5
1946 513.96060.7 143.6

[code]...

I know that once the data is indexed i can than use a double to find the average of the 12 specific pieces of data and so on. once this is complete i should than be able to transfer the data to a simple graph.

View Replies View Related

Reading Text File With Specific Input Format - Output Formatted Report

Apr 10, 2014

Here's a link to it : [URL] ....

The basic gist is it's "A program that reads in a text file that uses a specific input format and uses it to produce a formatted report for output."

Specifically :"For this lab you will write a Java program that produces a simple formatted report. The program will prompt the user to enter a file name. This file must contain information in a specific format (detailed below). Each "block" of the file contains information for one player in a competition -- the name of the player followed by a number of different scores that that player achieved. The program should find each player's average score, median score and best and worst scores and display them in a line on the final summary report. The program should also determine which player has the highest average score and which player has the lowest average score."

I get the following errors when I try and compile it:

Enter an input file name: Project11.txt
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException... -1
at java.util.ArrayList.elementData(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at Project11.getMedian(Project11.java:68)
at Project11.main(Project11.java:27)

I get that the error(s) reside in lines 68 and 27, among problem other areas, but I'm not exactly sure how I can fix them.

Here's my code:

import java.io.*;
import java.util.*;
public class Project11 {
public static void main(String[] args) throws IOException{
Scanner in = new Scanner(System.in);
System.out.print("Enter an input file name: ");
String input = in.nextLine();

[Code] ....

View Replies View Related

How To Check For A String In The File And Get Start And End Line Numbers

Aug 13, 2014

write the logic in the below given Java method.

Public static boolean updateNetMap(String filepath, String nodename){

// check the file pointed by filepath to have entry for nodename.
// if it is there, get the start line no and end line no
// Based on the line nos, need logic to remove the contents from the file.
}

Below is the sample node entry, which we need to identify and delete (here nodename is WAS_CD1):

WAS_CD1:
:conn.retry.stwait=00.00.00:
:conn.retry.stattempts=6:
:conn.retry.ltwait=00.00.00:
:conn.retry.ltattempts=6:
:tcp.max.time.to.wait=0:

[Code]...

View Replies View Related

How To Read Something Specific Of A Web Page

Feb 28, 2014

I am trying to have a program go on one of the stock trading websites and read the number a stock or currency is at and display or save it. I have it reading and displaying the binary code but I don't see how to have it find the numbers I would like to get.

On the site you would have to go on the page and click some tabs to trade and maybe the stock you would like, it doesn't really matter what one it returns as this is more just an idea. Although I would like to have it search out a selected stock eventually to take it to the net level. I think my biggest problem is I can't see how to access the stock numbers in the code. I looked for different click events but don't see how to have a program do this.

I do not intend to have it display all the code like it is now. I just did it like that to see what I was getting. I will just have a small toolbar with options and a display.

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
public class StockTracker {
public static void main(String[] args) {
 
[Code] ......

View Replies View Related

Splitting Array By Specific Value

Jan 15, 2014

How do you split an array by a specific value.

For instance this is my array: "4*6*9*89"

How can I take out "*" and therefore split up all the values like this: "4" "6" "9" "89"

View Replies View Related

Using Loops To Create A Specific Design?

Sep 10, 2013

I am completing the exercises in Java How To Program 8th Edition by Harvey and Paul Deitel.There are two optional exercises GUI and Graphics Case Study Exercises on page 141 Chapter 4.

I have to use loops and control statements to draw lines thereby creating two designs.I am trying to create the design on Fig. 4.20. The lines do not line up correctly.The lines should fan out from all corners. Individually, they look exactly like it should.

Example of one corner.

int width = getWidth();
int height = getHeight();
// upper-left corner
int startX = 0;
int startY = 0;
int endX = 0;

[Code] ....

For the other corners I have different starting and ending positions.To draw upper-left corner I have a starting position of 0,0 and ending position of 0,height.I then move ending position up one vertical step and right one horizontal step. I repeat this fifteen times.

To draw upper-right corner I have a starting position of width,0 and ending position of width,height. I then move ending position up one vertical step and left one horizontal step.

To draw bottom-left corner I have a starting position of 0,height and ending position of 0,0. I then move ending position down one vertical step and right one horizontal step.

To draw bottom-right corner I have a starting position of width, height and ending position of width,0. I then move ending position down one vertical step and left one horizontal step.

For the second design Fig. 4.21 all my lines line up correctly no matter the direction I resize it. Both designs frame size is 250,250. Both designs are divided into fifteen steps.

View Replies View Related







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