I'm using SWI-Prolog with the JPL library.
I have a program written in Java that produces strings like these:
fact(1,2)
fact(2,3)
fact(1,3)
Then, there is a prolog file that needs this facts in the head of file.
I do not want neither insert the code in the head of file, nor use a text file, but only java.
Is there a solution for this?
If I'm reading this correctly, you need to write Strings into a Prolog file from Java?
Java can write into many files types including .txt, .word, and html. You can attempt to write to a Prolog file by using the extension name.
FileWriter exampleFileWriter = new FileWriter("exampleProlog.pl");
Just write the Strings, then close the file. There are many safer and better ways to writing to files in Java. Just look at this:
Fastest way to write to file?
http://www.javapractices.com/topic/TopicAction.do?Id=42
EDIT: This might be of help:
How use Prolog from Java?
Related
I'd like to redirect my Java Eclipse's console output to a CSV file.
I know how to do that for a TXT file (Run Configurations-Common-etc.), but I can't find how to get a CSV file.
Thanks a lot.
There is no support for this in Eclipse.
Console output is generally not in a format suitable for a CSV file. It is up to you to add code to your program to generate the correct format for CSV.
I dont know if it helps, but csv is basicly txt. You can separate your output by ";" in compile time, output it to txt and then just save it like CSV.
I think whatever you are printing on the console, you can just use one of these solutions to write it in CSV format and that's pretty much it.
1> Simple Solution: If you are sure the CSV files doesn’t contain “separator or double-quotes”, just use the standard split() to parse the CSV file.
2> Advance Solution: This solution will solve the field containing “separator or double-quotes” issue, and also support the custom separator and custom enclosed field. Review the following CSV parsing example and also the JUnit test cases to understand how it works.
3> OpenCSV Example: If you are not comfortable with above simple and advance solution, try using third party CSV library – OpenCSV.
https://www.mkyong.com/java/how-to-read-and-parse-csv-file-in-java/
Don't use System.out.println() but define a PrintStream that you use somewhere, so it becomes myOut.println().
Or better, use a logger-library for it, for example log4j, or even a facade: slf4j
Hi I need to view code of an .exe file which has to be loaded dynamically. So, is there any method of obtaining source code of an exe file in Java or do I need another language to do that?
Standard Java will presumably not be able to do this because what you want to do is platform specific.
I don't know any library that is able to do this.
What you could do is take the exe, extract its code segments and compare their content to a list of opcodes. You could then for example simply iterrate over the bytes and create a list how often hex 0x90 is found, which is an indication for a nop.
Perhaps it is a better solution to simply disassemble the file (into "sourcecode") and count the occurences based on their text representation.
I have some pig output files and want to read them on another machine(without hadoop installation). I just want to read a tab-seperated plain text line and parse it into a java object. I am guessing we should be able to use pig.jar as dependency and be able to read it. I could not find relevant documentation. I think this class could be used? How can we provide the schema also.
I suggest you to store data in Avro serialization format. It is Pig-independent and it allows to handle complex data structures like you described (so you don't need to write your own parser). See this article for examples.
Your pig output files are just text files, right? Then you don't need any pig or hadoop jars.
Last time i worked with Pig was on amazon's EMR platform, and the output files were stashed in an s3 bucket. They were just text files and standard java can read the file in.
That class you referenced is for reading into pig from some text format.
Are you asking for a library to parse the pig data model into java objects? I.e. the text representation of tuples & bags, etc? If so then its probably easier to write it yourself. It's a VERY simple data model with only 3 -ish datatypes..
Basically, I want to be able execute a byte stream as a file, without writing said bytes to a file.
I want to do this in a windows environment.
You could say I want a to create a file, copy the stream to the file, and open the file as an executable, but I want the file to have no physical manifestation on the disk.
Thanks
This is not possible to do using the standard Java API. You will have to rely on some OS specific native implementations, either that do the whole thing for you, or that allow you to create some sort of RAM-disk on which you can place your temporary data and execute it.
Possibly related:
write file in memory with java.nio?
Supposing you bytestream is the one of a standard exe, and you don't want to call a whole virtualisation environnement, the short answer is no because internal adresses in the code wouldn't map.
Here's a more detailled answer :
process.start() embedded exe without extracting to file first c#
I need to parse an Encapsulated Post Script file into Java program. More specifically, I need to be able to extract simple vectors and curve elements from it, and manipulate them after this. Is there a Java library which can do this?
ToastScript looks like it may be what you are looking for.