Je crée un canal nommé en utilisant JNI en appelant la commande mkfifo(). J'utilise le mode = 0666.Impossible de lire le tube nommé en Java
J'essaye alors d'écrire dans le tuyau en utilisant Java, mais je suis bloqué en écrivant dans le tuyau. Je suis bloqué à la ligne suivante et je ne peux pas la dépasser. Je ne reçois aucune erreur non plus.
PrintWriter out = new PrintWriter((new BufferedWriter(new FileWriter(pipePath))));
Veuillez nous aider.
Cordialement,
-H
PipePeer.java
import java.io.*;*
public class PipePeer {
private native int createPipe(String pipeName, int mode);* // --------> native method to call mkfifo(pipeName, mode);
static {
System.load("/home/user/workspace/Pipes/libpipe.so");
}
public static void main(String[] args) {
PipePeer p = new PipePeer();
PipeImplement pi = new PipeImplement();
String pipePath = "/home/user/workspace/Pipes/pipeFolderpipe1";
int mode = 0777;
int createResult = p.createPipe(pipePath, mode);
if (createResult == 0)
System.out.println("Named pipe created successfully");
else
System.out.println("Error: couldnot create Named pipe");
String pipeLocation = "/home/user/workspace/Pipes/pipeFolder/pipe1";
pi.writePipe("From Java", pipeLocation);
System.out.println(pi.readPipe(pipeLocation));
}
}
PipeImplement.java
import java.io.*;
public class PipeImplement {
public BufferedReader in;
public void writePipe(String strWrite, String pipePath){
PrintWriter out = null;
try {
//-------------> cannot go past this line <--------------------
out = new PrintWriter((new BufferedWriter(new FileWriter(pipePath))));
} catch(IOException e) {
System.out.println("error while writing");
e.printStackTrace();
}
out.println(strWrite);
System.out.println("writen");
out.close();
System.out.println("close");
}
public String readPipe(String pipePath) {
try {
in = new BufferedReader(new FileReader(pipePath));
}catch (FileNotFoundException e) {
e.printStackTrace();
}
String lineRead = "";
try {
lineRead = in.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return lineRead;
}
}