I have to recursively find a given string in a file. I HAVE to use the LineNumberReader class, and the output would be like so:
Line#Found : the string of the whole line
This is the code I've written:
public String findGivenString(String givenString, int currentLineNumber) {
LineNumberReader lnr = null;
try {
lnr = new LineNumberReader(new FileReader(getFile()), 4096);
lnr.setLineNumber(currentLineNumber);
String s = lnr.readLine().toLowerCase();
[Code] ....
I messed around with a bit, and it doesn't change to the new set line. Though the line number is incrementing! So it just keeps checking the first line of the file over and over again, which is why it can't find the given string. Which also throws the StackOverFlow exception I'm getting.
Here's the output if I remove the comment from the System.out...:
String @ that Line# 1: package banking;
String @ that Line# 2: package banking;
String @ that Line# 3: package banking;
String @ that Line# 4: package banking;
....
So you see it keeps checking the same line even though the line number IS incrementing.
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)
I have a case: i have to make fast searching of a file in to all file systems(Linux or Windows). I use search directories recursively for file. Is there a quick way?
if(Directory.getText().matches("")){ JOptionPane.showMessageDialog(null, "Please search for the directory"); } else if(fileName.getText().matches("")){
[Code].....
This is actually my question:
Java Code:
1. billing-20140527[09].txt has
a)XGMS,2014-05-27 10:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040. b)XGMS,2034-05-27 30:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040.
2. billing-20140527[10].txt has
a)XCGS,2014-05-27 10:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040. b)HELO
[B]I try to find the number 1 in both text files, if lets say I input the text file name is billing, I can find the number 1 in both text file and output them:[/B]
a) XGMS,2014-05-27 10:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040. b) XCGS,2014-05-27 10:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040.
[B]However, if I specify the text file name: billing-20140527[09].txt and find the number 1 inside the text file, it will only output:[/B]
a) XGMS,2014-05-27 10:08:04,122,PLAYER_VERIFY,VERIFY to LBA,0x580000,0xC0000,253040. mh_sh_highlight_all('java');
I have included split() to put a string read from a given file into indexed array. Looking for a word position (not char position number in addition to the line number I have already written. Line number works fine, however word position isn't quite right.Below is my code:
import java.io.*; public class Word implements Comparable, TreeComparable{ String word; int count; int wordpos; ObjectList lines; private SuperOutput so;
My requirement is to find the line number using multiline string. Here I need to extract the string between FROM and where clause(from the below string) and need to find the line number in the file
SELECT HL.LOCATION_ID,HPS.PARTY_SITE_ID,HCAS.CUST_ACCT_SITE_ID INTO LN_SITE_LOCATION_ID,LN_LOC_PARTY_SITE_ID,LN_CUST_ACCT_SITE_ID FROM HZ_LOCATIONS HL, HZ_PARTY_SITES HPS,
i tried everything but its giving me errors. i tried the for loop but its giving me something else.
this is what i have to do Write a recursive method that prints out the data elements of a linked list in reverse order.
Your method should take in as a parameter the head reference to a linked list. Then, write a recursive method that returns a count of the number of elements greater than a given threshold. You may assume that the data elements in the linked lists are ints. The parameters of your method are a reference to the linked list and a int value representing the threshold.
public class recursion3 { public static void main(String [] args) { char a [] = {'A', 'B','C','D','E'}; System.out.println(a); } public static String reverseString(String s) { if (s.length() <= 1) {
I just can't seem to figure it out how to solve this inherently recursive assignment.The task is to check a directory path and read the files within that path; also, if there are more directories within it, we have to go deeper into those directories to read the files within them - if any. What you're looking at is my skeleton of the assignment:
public class SearchingForStrings {
public static void main(String[] args) { String path = "."; // Default File sf = new File(path); String mainDirectory = args[0]; // These two are just String keyString = args[1]; // command-line arguments
It was quite recently that Data Structures was introduced to me, so I started out writing some iterative programs recursively.I found some strange output which shouldn't have come out but if you take a look at these three codes
long factorial(long n) { if(n == 1) { return 1; } else { result = n*factorial(n-1);
[Code] ....
These are three versions of the code, achieving the same objective of obtaining a given number and returning the factorial, but in spite of the changes made to the code, they produce the same result. I needed a reason as to why it is so? I tried to dry run all the codes but at some point or the other I got confused, and had to start all over again and couldn't come up with a proper result.
My program is supposed to use recursion and iteration to sum and reverse elements in an array of Longs. The array is supposed to be 1000000 cells and I am supposed to compute the average times of 99999 trials. When I try to run the program, it keeps saying running.... but doesnt ever do anything.
public class PA2Delegate { private long[] start; private long[] end; private Long reversal; private Long sum = (long)(int)0;
SimpleDotComTestDrive.java:8: error: cannot find symbol String result = dot.checkYourself(userGuess); ^ symbol: method checkYourself(String) location: variable dot of type SimpleDotCom 1 error
Code:
public class SimpleDotCom { int[] locationCells; int numOfHits = 0; public void setLocationCells(int[] locs) { locationCells = locs; } public String checkYourSelf(String stringGuess) { int guess = Integer.parseInt(stringGuess); String result = "miss"; for (int cell : locationCells) {
I have got a pretty good framework working for my hangman game so far, however I am quite stumped on how to find multiple instances of the same letter in a single string. I am using indexOf to find the instance of a character in a string, but it only returns the first instance. So if the words(s) contain(s) multiple instances it doesn't register the rest.
public static void main(String[] args) { String word = "crazy horse"; String answer=""; String space=" "; String dash="-";
I'm getting this -file not found- error despite the fact that I have saved the file with appropriate permissions in the src folder of the given application in netbeans. The program prompts for a listings.txt file to read and write data to a new file that counts and sums the info in a overview.txt report. Here is the stacktrace:
run:
Type in the name of the file: listings There was a problem:java.io.FileNotFoundException: listings.txt (The system cannot find the file specified) java.io.FileNotFoundException: listings.txt (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:131) at java.io.FileInputStream.<init>(FileInputStream.java:87) at java.io.FileReader.<init>(FileReader.java:58) at kettask2a.KetTask2a.main(KetTask2a.java:48)
I'm trying to find a specific file that already exists on the computer. I want to find that file and zip it. don't get sidetracked with whether or not the file exists, because I'm sure it does on my local machine and TDD will address that what-if scenario later.
My code and JUnit is below. Since its not finding the file, I assume I must be formatting 'path' wrong. I wonder if I'm even on the right track logically.
private ZipParameters zp = new ZipParameters(); private ZipFile zipFile; public ZipFile createZipFile(File f, String path) throws ZipException{ zipFile = new ZipFile(path); zp.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); zp.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
I'm trying to read a .xlsx file using Apache Poi on Eclipse and store the data into an ArrayList.
My code :
import org.apache.poi.ss.usermodel.*; import java.io.*; import java.util.*; public class parseReadFiles { public static void main(String[] args) {
[Code] ....
I keep getting a FileNotFoundException: Users/Divjot/Desktop/first.xlsx (No such file or directory). I've tried different combinations of file names and paths but can't get the program to find it. Should the file be stored in a special place or should the class path be different?
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:
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.
I am working through a text and I am supposed to complete the following tasks.
Your ReadFiles.java class requires the following methods:
Method: check to see if the file exists
Method: find number of rows in csv file
Method: Converts the csv file to a mutli-dimensional array
Method: PrintArray
Method: Return array using a get method
Create a file DataAnalyzer.java. This file will be used to call the methods in ReadFiles.java. Be sure to demonstrate that all of your methods work through DataAnalyzer.java.
The problem is that it does not really provide any information on how to go about reading a file into an array. I am stuck at the third task of converting the file to an array and I have tried several ways to do this unsuccessfully. I thought that I would at least try to get things to print out (line 87) to see if I could get that to work, but all that prints in null over and over again.
Java Code:
public class DataAnalyzer { public static void main (String[] args) { ReadFiles aReadFiles = new ReadFiles(); aReadFiles.fileCheck(); aReadFiles.findRows(); aReadFiles.convertFile();
class mmm { public static void main(String[] args) { OcrEngine ocr = new OcrEngine(); ocr.setImage(ImageStream.fromFile("pp.tif")); // ocr.setImage((IImageStream) new File("pp.tif"));
[Code] ....
In above code giving error .
Exception in thread "main" com.aspose.ms.System.IO.FileNotFoundException: Can't find file: pp.tiff.
Where i am wrong. I am trying to pass all formt(.png,.gif,.jpg) images. I am giving proper path ....