Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can I run a file (like an exe program) using java? I have searched up how to open a file (even on oracle docs) to no avail. Is there a class to help me with this? I tried
try
{
Runtime rt = Runtime.getRuntime() ;
Process p => rt.exec("Program.exe") ;
InputStream in = p.getInputStream() ;
OutputStream out = p.getOutputStream ();
InputSream err = p.getErrorStream() ;
p.destroy() ;
}
catch(Exception exc)
{
}
But it didn't work
Try this
Runtime.getRuntime().exec("c:\\program files\\test\\test.exe", null, new File("c:\\program files\\test\\"));
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to open MATLAB File(.m) using Java
I know MATLAB API.
It's a shame, but I don't know how to use it. How can I open MATLAB File(.m) using MATLAB API?
What should I do?
If possible, can you show an example code?
Thank you.
calling matlab function in java
1-first, add matlab as an Environment variable in windows.
in win10: search Environment variable, Edit environment variable, system variables, path, edit, new, ...
add [matlabroot]/bin/win64 to the path variables.
2-import matlab engine in your java class and use MatlabEngine and its functions :(eval,evalAsync,feval,...) :
import com.mathworks.engine.*; //import engine
public class javaEvalFunc {
public static void main(String[] args) throws Exception {
try{
MatlabEngine eng = MatlabEngine.startMatlab();
eng.evalAsync("[X, Y] = meshgrid(-2:0.2:2);");
eng.evalAsync("Z = X .* exp(-X.^2 - Y.^2);");
Object[] Z = eng.getVariable("Z");
eng.close();
}catch(Exception e){}
}
}
3-to call a specific .m routine, call it with its full path with eval,...
eng.eval("c:\temp\myroutine");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Please suggest How can I improve my question
I ran my code but it throws cannot find main class error. I know this error comes when name of class with main method is different from file name. I tried to solve this error for an hour. I need help.
CountRows.java
import java.io.*;
import java.sql.*;
public class CountRows
{
public static void main(String args[])
{
System.out.println("Count number of rows in a specific table!");
Connection con = null;
int count = 0;
try
{
//Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial","root","dics");
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Execution
>javac -classpath "e:\softwares\java\jar files\mysql-connector-java-8.0.19.jar" CountRows.java
E:\user\java\jdbc\test>java -classpath "e:\softwares\java\jar files\mysql-connector-java-8.0.19.jar" CountRows
Error: Could not find or load main class CountRows
Edit: Although the solution works but I still don't understand what was wrong with my way of executing code
Your Code is working perfectly fine there is no issue in it.
I suggest you set classpath initially before using javac and java tools.
Set your classpath via CMD
set classpath="<EXTERNAL_JAR_FILES_PATH>"
I hope this might help you. If you are still facing the same issue you can ping me back. I will be happy to help you.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
It happened that someone filled form and attached file with virus. Our application only checks file extension and size and nothing else is validated. Uploaded files could be checked with some antivirus or something...
What is the best solution here?
I'm using https://github.com/philvarner/clamavj. Download ClamScan.java and ScanResult.java.
and then I have somelike this this to call it (untested):
protected ScanResult.Status virusScanFile(File file) {
ClamScan clamScan = new ClamScan(clamAVHost, clamAVPort, clamAVTimeout);
ScanResult scanResult = null;
if (clamScan.ping()) {
try (InputStream inputStream = new FileInputStream(file)) {
scanResult = clamScan.scan(inputStream);
} catch (FileNotFoundException | IOException e) {
logger.error(e.getStackTrace());
}
} else {
throw new RuntimeException("Could not scan file as ClamD did not respond to ping request!");
}
ScanResult.Status scanResultStatus = null;
if (scanResult != null) {
scanResultStatus = scanResult.getStatus();
}
return scanResultStatus;
}
If you need to install ClamAV on windows for development purposes then this may work for you:
Download http://oss.netfarm.it/clamav/ which contains clamd.exe;
Download http://www.clamwin.com/ which is the Windows version of ClamAV and contains the virus definitions updater (freshclam.exe);
Install both applications as normal;
Copy clamd.conf to C:/Clamav and edit as follows:
LogFile C:\Program Files (x86)\ClamWin\bin\clamd.log
DatabaseDirectory C:\ProgramData\.clamwin\db
Open a cmd prompt with Administrator priviledges and 'cd' to the
Clamav folder where you will find clamd.exe;
type "clamd.exe --install" (no quotes);
Open the Windows services and set "ClamWin Free Antivirus Scanner
Servce" to autostart.
Otherwise just connect to a Linux install via the clamAVHost and clamAVPort parameters, the values of which you will need to define.
You could probably use something like Clamscan and use their command line tool to point to any file that you want or include a script in your application that does the checking.
clamscan OPTIONS File/Folder
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
This code works in Eclipse, but when I try to submit the 'Test' problem on the SPOJ site, it gives me a compilation error.
Can you please tell me why?
public class Test{
public static void main(String [] args)
{
java.util.Scanner input=new java.util.Scanner(System.in) ;
int n ;
while(true )
{
n =input.nextInt() ;
if(n==42)
break ;
else
System.out.println(n) ;
}
}
}
You have to name your class "Main" for it to work on SPOJ.
See this forum post for more information: https://www.spoj.com/forum/viewtopic.php?t=37
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
getting two error when trying to compile programm using commandline
error-Shuffle1.java:24 error:package System does not exist
System.out.print("b c")
Shuffle1.java:31 error:package System does not exist
System.out.print("b c")
letter in word Sytem is also capital then too getting error
public class Shuffle1
{
public static void main(String[] args)
{
int x=3;
while(x > 0){
if(x > 2){
System.out.print("a");
}
x=x-1;
System.out.print("-");
if(x==2){
Sytem.out.print("b,c");
}
if(x==1){
Sytem.out.print("d");
x=x-1;
}
}
}
}
It is
System.out.print
NOT
Sytem.out.print
Cause you wrote Sytem instead System