creating a silent wav file with ffmpeg - java

i want to know how to create ffmpeg file that is silent for a certain length that is dependant on a variable called DIFF, this is what i got so far that doesn't seem to work
// creates a wav file for the lenth of the silence
File silence = new File(root + "silence.wav");
String lthacommand = "ffmpeg -filter_complex aevalsrc=0 -t " + diff
+ " " + silence.getAbsolutePath();
new ThreadControl().executeCommand(lthacommand);

Related

Alternative ways to rename a flat file in Java

So im writing a program that reads a txt file that the user provides the name of from a specific folder
I want to rename the .txt after the user has opened it. However, nothing happens
temp = userInput;
currentFileDir = "D:\\Document\\" + username + "\\" + temp1 ;
File directory = new File(currentFileDir + ".txt");
Scanner readingFile = new Scanner(directory);
while (readingFile.hasNextLine())
{
txtdata = txtdata + readingFile.nextLine() + " ";
}
File newName = new File(currentFileDir + "--OPENED.txt");
directory.renameTo(newName);
System.out.println(txtdata);
}
Is there something wrong with the code I provided?
I've tried using it in a standalone program and it works fine, so I think that the rest of the code of my program must interfere with the rename process.
Are there any alternatives to "renameTo"?

How to pass arguments to pre compiled java code

I need to process a high volume of resumes. And want to use this parser:
https://github.com/antonydeepak/ResumeParser
But you run it in powershell with the file to read and the output file.
But I do not know how to automate this, so it read a whole folder containing the resumes.
I know some Java, but cant open the code. Is scripinting in powershell the way to go?
Thanks!
> java -cp '.\bin\*;..\GATEFiles\lib\*;..\GATEFILES\bin\gate.jar;.\lib\*'
code4goal.antony.resumeparser.ResumeParserProgram <input_file> [output_file]
Either make a batch file from an edited directory listing, or write a program.
As this is stackoverflow:
So starting with the same classpath (-cp ...) you can run your own program
public void static main(String[] args) throws IOException {
File[] files = new File("C:/resumes").listFiles();
File outputDir = new File("C:/results");
outputDir.mkDirs();
if (files != null) {
for (File file : files) {
String path = file.getPath();
if (path.endsWith(".pdf")) {
String output = new File(outputDir,
file.getName().replaceFirst("\\.\\w+$", "") + ".json").getPath();
String[] params = {path, output);
ResumeParserProgram.main(params);
// For creating a batch file >x.bat
System.out.println("java -cp"
+ " '.\\bin\\*;..\\GATEFiles\lib\\*;"
+ "..\\GATEFILES\\bin\\gate.jar;.\\lib\\*'"
+ " code4goal.antony.resumeparser.ResumeParserProgram"
+ " \"" + path + "\" \"" + output + "\"");
}
}
}
}
Check that this works, that ResumeParserProgram.main is reenterable.

Importing .sql file into MySQL using Java code

I'm trying to programmatically import a .sql file into MySQL. The .sql file was generated by mysqldump. I'm trying to do this dynamically in a Java program. But, it keeps failing on the "<" character within Java (I think). If I grab the String in the debugger of the command it's about to run (the "combined" variable below), and paste it into the command line, it works fine. Likewise, when I was trying to get the mysqldump working inside this program, it failed on the ">" character, and I had to replace it with the "--result-file=" argument to get it to work.
String command = mySqlPath + "mysql.exe";
String user = "-u " + settings.dbUser;
String password = "-p" + settings.dbPassword;
String db = settings.dbDatabase;
String inputFile = filePath + mySqlDumpFile;
String combined = command + " " + user + " " + password + " " + db + " < " + inputFile;
ExternalCommandExecuter ece = new ExternalCommandExecuter(combined);
int code = ece.execute();
This results in this String for example
C:\software\mysql5\bin\mysql.exe -u root -p<password>
db_name < C:\software\tomcat7\webapps\ROOT\WEB-INF\documents\dump-1461789460425.sql
Which will result in a exitCode of 1. Pasting it into the command line, and it'll work.
So I couldn't get it to work in Java by importing the file with a "<", instead I had to write an external .sh/.bat file which I call from my Java code.

Unix: "ls" command shows files with ? after the extension

I have written a shell script (test.sh) using Java. This shell script actually does a copy job from one file to the other. After the execution of the shell script I have opened the directory from Console and typed ls. It shows the output file with ? after the extension.
example : foo.csv?
File execFile = new File(file);
FileWriter fwFile;
try {
fwFile = new FileWriter(execFile);
execFile.setExecutable(true);
BufferedWriter bwFile = new BufferedWriter(fwFile);
bwFile.write(strOutput.substring(0, 2));
bwFile.write("\r\n");
bwFile.write("cd " + strOutput);
bwFile.write("\r\n");
bwFile.write("mkdir " + strOutput);
bwFile.write("\r\n");
bwFile.write(strUnixPath);
bwFile.write("\r\n");
bwFile.write("cd " + strWorkingPath + IPlatinumConstants.FS+"lib"+IPlatinumConstants.FS+"Unx");
bwFile.write("\r\n");
bwFile.write("echo Cut Src Start time %time%");
bwFile.write("\r\n");
bwFile.write("cp " + " \"" + strSourceFilePath + "\" \""
+ strOutput + "copy_A\"");
bwFile.write("\r\n");
My guess is that, while creating the shell script using java, something needs to taken care of
bwFile.write("\r\n");
replace these lines with UNIX line endings
bwFile.write("\n");
or set the proper line separator
System.setProperty("line.separator", "\n");
bwFile.newLine()

Code cannot find my file

I have written a short program that will find a file I have made and print some of its details. It executes all right, but it cannot detect the file size or if it is hidden or not. E.G.
file path: C:\temp\filetext.txt last modified: 0 file size: 0 Is file hidden?false
The file does exist in the temp folder on C. I'm not really sure what the problem is
public void Q1()
{
String fileName = "filetext.txt";
getFileDetails(fileName);
}
public void getFileDetails(String fileName)
{
String dirName = "C:/temp/";
File productsFile = new File(dirName + fileName);
long size = productsFile.length();
System.out.println("file path: " + productsFile.getAbsolutePath() + " last modified: " + productsFile.lastModified() + " file size: " + productsFile.length() + " Is file hidden?" + productsFile.isHidden());
}
File does not need a physical file to work with. Therefore your File object can exist even if the physical file it is supposed to represent does not exist/cannot be found. Check the JavaDoc for length() and lastModified(), they both return 0L in case for example the file does not exist. So make sure your File objects is linked to an existing file on your file system by calling file.exists() before calling the other methods.

Categories

Resources