Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I know there is already some posts about this but none of them answered my question.
Here's the situation, I have program written in C but I developped my GUI in java. So what I need to do, is calling my C program when I click on a button or a combobox.
In order to do that, is it possible to just compile the C program and then call it in my java interface ? (and if it is possible, how do I do that ?).
Or do I have to use JNI ? (I've read some posts about it but it seemed quite complicated to learn it for just one project).
To have maximum interoperability you should use JNI, but as a simple approach just compile C code and call C executable from JAVA with Runtime.getRuntime().exec().
if you are under UNIX to read response you could do something like this:
String line;
Process p = Runtime.getRuntime().exec( "/path/to/C/executable" );
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
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 2 years ago.
Improve this question
I need to use this code in .net Framework 2.0 but the problem is that labmdas(WHERE) can't be used in this version, is there a way?
var serializer = new JavaScriptSerializer();
retorno = serializer.Deserialize<RespuestaCvt>(respuesta);
var soloServidores = retorno.Rows.Where(x => listaEstados.Contains(x.EstadoId)).Where(x => listaTipos.Contains(x.TipoId)).ToList();
return soloServidores;
Since Lambda expressions were not available until C# 3 you will have to change the way you do the actual row filtering. Since you're returning List<> we can just go back to the pre-LINQ way of doing things:
var soloServidores = new List<TheRowType>();
foreach (var row in retorno.Rows)
{
if (listaEstados.Contains(row.EstadoId) && listaTipos.Contains(x.TopiId))
soloServidores.Add(row);
}
return soloServidores;
Of course you could do it the hard way and extract the lambda to a static method then implement a suitable Where(...) extension... but if you're going to try to emulate C# features from a later language version then you're usually better off migrating your project to that later version.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So let's say I have a CSV file of random alphabets in columns for example's sake:
a
wrrq
jt
pkto
b
They are in String format and I want to be able to find the minimum String length in this CSV list. In the example given, the minimum being 1 (the maximum being 4). Then I want to print all the minimums in order, resulting in:
a
b
This is my code that reads each line from the top and it's barely anything to a helpful guideline but I'm kind of stuck right now.
BufferedReader br = new BufferedReader(new FileReader("Example.csv"));
while ((nextLine = br.readLine()) != null) {
...
}
Is there a way to do this a simple way without using fancy 3rd party scripts. Maybe putting them into an array and then working from there perhaps(?) Keeping in mind that the minimum may not always be 1.
For a single-pass solution…
Create an empty collection to store results. Read first line, and store it in collection.
Read another line.
If this line is the same length as previously stored line, add to collection.
If longer, ignore.
If shorter, empty collection and then add.
Lather, rinse, repeat.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to look into a binary file.
I need to parse it in order to read some chars that the file contains.
Please any hint of how could I do it?
Thanks!
To be more specific I am looking for a particular sequence of chars in the file.
I suggest using a BufferedReader:
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
int index;
while(line = br.readLine() != null) {
index = line.indexOf(string);
if (index != -1) break;
//Assuming your file has some sort of key/value data
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to build a program, which can log the programs or threads running in windows. I would like to write the program in java.
Does anyone know such mehtod?
Try like this:
Process p = Runtime.getRuntime().exec
(System.getenv("windir") +"\\system32\\"+"tasklist.exe");
BufferedReader input =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null)
{
System.out.println(line);
}
run "tasklist" cmd using runtime instance.
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 9 years ago.
Improve this question
I have encountered the following error while compiling my Demo code on DataInputStreamDemo:
error:
i= Integer.parseInt(dis.readLine()) [Deprecated]
//where dis = reference DataInputStream obj
Reason for the method being deprecated :
This method does not properly convert bytes to characters.
Solution
Existing code : DataInputStream d = new DataInputStream(in);
Modified code : BufferedReader d
= new BufferedReader(new InputStreamReader(in));
refrences
The javadoc for this method makes it reasonably clear why it's deprecated, and has been for a long time, and suggests a better alternative.
Quoting from the Javadoc:
This method does not properly convert bytes to characters. As of JDK 1.1, the preferred way to read lines of text is via the BufferedReader.readLine() method. Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form:
DataInputStream d = new DataInputStream(in);
with:
BufferedReader d
= new BufferedReader(new InputStreamReader(in));