Renaming Log Files Program [Beginner] - java

I would like to make a simple eclipse/java program which goes through a folder with many log files and renames each log file based on strings of text found inside the log file.
The log files are all text files, but are named .log.
Here is a screenshot of the folder containing the log files:
Here is a screenshot of an individual log file. In this case, I would like this log file to be renamed "EFT Daily Activity Report," which shows up in each line.
The problem is I don't know how to go through folders in eclipse/java to access each of the files.
EDIT: Why doesn't this work? Am I missing something with the directory? Sorry, I'm new to local directories in java :)

You can have a look at the following tutorial for File:
http://tutorials.jenkov.com/java-io/file.html
If I understand your question correctly, the last example should be what you are looking for.

Related

Given property file not found

so I'm trying to run my program and I keep getting the error when I run my main class it says that given property file isn't found, below are two images of the file location and the arguments I've putten in and the error that appears, I'm struggling to realize why the file isn't being located, any help?
Because Windows in its wisdom thinks that hiding extensions of known file types is a good ting. You files is called input_parameters.prp and inputs.in, I guess.
If you give those names it would probably find this files.
To be sure you can open a cmd or powershell windows and run the dir command in that folder to see the complete names.

How to intercept Tess4J's output and put it in a logfile?

I am using Tess4J JNA wrapper and I want its console output to appear in a logfile (any kind of text file).
tessInstance.setTessVariable("debug_file", "tesseract.log");
also I have a file called "logfile" in tessdata/configs/ with the following text:
debug_file tesseract.log
The result was simply Tesseract console outputs disappear, but no tesseract.log file.
I did these according to Tesseract-OCR's FAQ.
Tess4J does not have any documentation on how to properly set this in code. I couldn't even find a list of variables, but currently I am only interested in how to put console outputs of Tess4J into a text file through code.
EDIT: The following line of code will make the Tesseract's output disappear from console but the .log file has nothing in it and can't be deleted until the program is shut down.
That statement alone should suffice. Look for the file in your project's root directory. You can specify an absolute path, e.g., "C:\\Temp\\tesseract.log", if desired.

Log4j no file output

Bit of a newbie with Log4j please forgive me if I'm doing something daft.
Trying to get log4j to write logs to a file while I am still working on it in IntelliJ.
No issues with getting sl4j/log4j outputting to the console/stdout whatsoever, that's fine. Issue is with getting it to write those same messages to a log file.
Here is what I have:
My dependencies are, I think, in order:
I have created a logger:
I have added a log4j.propeties file in my resources:
I have added a reference to the log4j.properties file in the intelij run configuration (the redacted part is just a folder name):
And when I run the app I see that the logging is in place on the console/stdout:
But I do not get a log file ( mylogs.log)as a result of the 'file' appender. I've tried different log file paths but that makes no difference. I'm not sure whether I have to run the application a jar for this to work, perhaps?
In short, I'm not sure what I'm doing wrong and would appreciate any assistance.
Thanks!

Java Program to find image in .java or .jsp file

I have a project with around 50 java classes/files (this 50 files includes both JSP and Java files). In this files I have written code to display abc.jpg image on my JSP pages. Now I want to write a java program which will replace all the abc.jpg images by xyz.jpg image in my project. I have no clue how I can do this. Also suggest if there is any free tool available to do the same.
What you want to do, will be done using following steps. Please note that you can find information about each step in StackOverflow itself in different posts:
1. Create a traversal policy for a directory in which all files are present, to get path of all .java and .jsp files.
2. Read all files one-by-one and write its content to another temporary file line by line.
3. While reading individual line, check whether it contains the name of .jpg file whose name you want to update. If yes the replace the name with new name and write the current updated line in temporary file.
4. Once the file reading is completed, delete the original file and rename the temporary file to original one.
5. Now you will have a same file with updated names of .jpg files.
6. Repeat the steps from 2-5 until all files are read and write.
Hope this will help. And yes you have to search these methods in SO itself. :-)

how to define a file path in java to make it ready for production phase?

I am writing a program in java with netbeans IDE which receives a jasper report *.jrxml and then displays the report for the user. I wrote the following line of code for the file path
String reportSource = "src\\jasper-reports\\report.jrxml";
but when I move the dist folder in some other place and try to run the jar file inside it, my program can not find the report.
my problem is that were should I put the *.jrxml file and how to define it's path in my program so that when I want to give my software to someone else it runs without any errors (e.g. the program can find the file)
avoid using absolute paths. try to include the file as a resource in your netbeans project. then in your code you can search for and load the file as
new InputStreamReader((Main.class.getResourceAsStream("/report.jrxml")))
something like that depending on where the file resides in your project
it's more recommended using one of the two approaches:
pass the locations/paths as a -Dproperty=value in the Java application launcher command line http://www.tutorialspoint.com/unix_commands/java.htm
store it the locations/paths in a configurations file with a unique key and edit the file accordingly for different environments,
e.g.this files always stored in ${HOME}/config_files/ directory
absolute paths considered a bad practice

Categories

Resources