I'm new at Jlink (and English, so I'm sorry if things aren't clear).
I did a code which tries to scan a file searching for a given word. As a result, I'm supossed to get the line where the given word is found, but I get nothing in the notebook. Here's my code:
Needs["JLink`"]
Scanner[archivo_String, palabra_String] :=
JavaBlock[
Module[{entrada, conteolin = 0, conteopal = 0, sc, ruta, leer, lin,
st},
InstallJava[];
ruta = JavaNew["java.io.File", archivo];
sc = JavaNew["java.util.Scanner", palabra];
entrada = JavaNew["java.io.FileReader", ruta];
leer = JavaNew["java.io.BufferedReader", entrada];
lin = leer@readLine[];
While[lin != Null, st = JavaNew["java.util.StringTokenizer", lin];
conteolin = conteolin + 1;
While[st@hasMoreTokens[],
If[st@NextToken[]@equalsIgnoreCase[sc], conteopal++,
Print[sc <> "aparece en la linea" <> conteolin]];
lin = leer@readLine[];
]
If[conteopal > 0,
Print["La palabra" <> sc <> "aparece" <> conteopal <> "veces",
"no se econtró la palabara"]]
];
]
]
I don´t know if I wrote it wrong, the Jlink docs has info about the Modal and Modeless interaction, do I have to use one of them?
Thank you