Want to compare [.so] files in two apk's - java

I want to compare the names (text) of .so files in two apk's
I write a batch script for pulling the app. Now , the app is at a desired location. How can i compare .so files.I am using java.util.zip for unzipping purpose and then trying to compare the directory structure.
My code is
import java.io.*;
import java.lang.Runtime;
public class batchrun {
public static void main(String[] args) {
try {
String[] command = {"cmd.exe", "/C", "Start", "C:\\test1.bat"};
Process p = Runtime.getRuntime().exec(command);
}catch (IOException ex){}
}
}
and my batch file is
#echo off
cd C:\app1
set /p UserInputPath= enter path
adb pull %UserInputPath%
I am clueless as in how to proceed from here

Related

Error: [filename].txt (No such file or directory) when trying to read in a txt file in Java (Ubuntu cmd line)

So I'm writing a piece of code that reads in many addresses and then manipulates the data, line by line, then adds it to a Binary Search Tree. However, the file isn't being found no matter what I try. I know the txt file needs to be in the root directory, but (I'm a student) we're required to submit a .tar.gz containing the contents of a directory made specifically for the assignment so I suppose it needs to be in the submitted folder.
I've tried using the "normal" methods I used in IDEs, but they all return the same error.
My code (roughly - obviously you don't really need to see the BST/manipulation stuff), right now, but I've tried every other typical file read-in method:
import java.io.InputStream;
import java.io.*;
import java.util.Scanner;
public class PrintIt{
public static void main(String args[]){
try{
File inFile = new File("/bin/testdata.txt");
Scanner sc = new Scanner(inFile);
while (sc.hasNextLine()) {
String line = sc.nextLine();
System.out.println(line); //manipulation in place of this
}
sc.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
}
I really only need the reading in the file part - the BST stuff/manipulation is just for context, just in case it mattered/there's a better way than reading through each line of the file and adding each to the Tree.

How do i make this File I/O Java program run in Unix?

Below is the program that prints all the files & folders from the given path.
import java.io.File;
public class ListDirectoryRecursive{
public static void listRecursive(File dir){
if(dir.isDirectory()){
File[] items = dir.listFiles();
for(File item : items){
System.out.println(item.getAbsoluteFile());
if(item.isDirectory()){
listRecursive(item);
}
}
}
}
public static void main(String[] args){
/* Unix path is: /usr/home/david/workspace/JavaCode */
File dir = new File("C:\\Users\\david\\workspace\\JavaCode");
listRecursive(dir);
}
}
How do i make this java program run on Unix? What is the standard approach to make this program portable?
Edit: I guess, we know on any OS, user home directory is part of the environment setting with values like "c:\users\david" in windows and "/user/home/david" in Unix.
Take the directory as an argument via args:
File dir = new File(args[1]);
(checking of course that args.length is sufficient).
Then you can simply do
java ListDirectoryRecursive C:\Users\david\workspace\JavaCode
on Windows, and
java ListDirectoryRecursive ~david/workspace/JavaCode
on UNIX. This has the distinct advantage of allowing you use this program to list any directory, rather than being a hardcoded path.
Make the hardcoded absolute path C:\\Users\\david\\workspace\\JavaCode relative.
please dont harcode
File dir = new File("C:\\Users\\david\\workspace\\JavaCode");
use System.getProperty("user.home"); to get /usr/home/david or C:\Users\david\ directory
like
String path = System.getProperty("user.home") + File.separator + "workspace" + File.separator + "JavaCode";
File dir = new File(path);
thanks overexchange

ProcessBuilder delete and rename

I am having a ProcessBuilder that should delete File.txt and then rename NewFile.txt.
Problem is that both files are deleted. Any idea why and how to fix?
public class MyProcessBuilder {
public static void main(String[] args){
final ArrayList<String> command = new ArrayList<String>();
// CREATE FILES
File file = new File("File.txt");
File newFile = new File("NewFile.txt");
try{
if(!file.exists())
file.createNewFile();
if(!newFile.exists())
newFile.createNewFile();
} catch(Exception e){}
// force remove File.txt
command.add("rm");
command.add("-f");
command.add("File.txt");
// rename NewFile.txt to File.txt
command.add("mv");
command.add("NewFile.txt");
command.add("File.txt");
final ProcessBuilder builder = new ProcessBuilder(command);
try {
builder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
The issue is that you are running a single command, namely
rm -f File.txt mv NewFile.txt File.txt
This unconditionally deletes files named File.txt, mv and NewFile.txt.
You want to split this into two separate commands.
Better still, use File.delete() and File.renameTo(). This will not only give you more control, but will also make your code more portable.
ProcessBuilder.start creates one process. You need to call it twice because you have two commands: first with the first command and then with the second.
Incidentally, why are you not using Java's file API for this? It is a lot easier to do this from Java than to deal with the complexity of launching a separate process, not to mention more efficient.

cannot copy throught nio2 java copy function

1.Hello
What i really meant is that when i run this program i get an unknown file named'mm' in the desktop.The program is not working in the way which i wanted.i want to copy 'oo.txt' from 'nn' folder to 'mm' folder
import java.nio.file.*;
import static java.nio.file.StandardCopyOption.*;
import java.io.*;
public class ListOfNumbers {
public static void main(String[] args)
{
Path p1 = Paths.get("C:\\Documents and Settings\\Administrator\\Desktop\\nn\\oo.txt");
Path p2 = Paths.get("C:\\Documents and Settings\\Administrator\\Desktop\\mm");
try{
Files.copy(p1,p2,REPLACE_EXISTING);
}catch(IOException e){
System.err.println("ff");
}
}
}
I guess this is the problem line
Path p2 = Paths.get("C:\\Documents and Settings\\Administrator\\Desktop\\mm");
I guess you are trying to copy the file with the same name to "mm" folder. If this is the case then you need to specify the name of the file. What is happening is that the file copy function is copying the file as "mm" on your Desktop folder. To verify open your file in NotePad and see the contents..
Just change the line as
Path p2 = Paths.get("C:\\Documents and Settings\\Administrator\\Desktop\\mm\\oo.txt");
and you should be fine.

Running java application in terminal window: No such file or directory?

I am using Eclipse for java and I just created a program I am trying to run on the terminal window for Mac. Every time I try to run it I get a No such file or directory. In the terminal window I moved to the source folder. Is this where I am supposed to be to run java programs from Eclipse? My command is listed below with the two text files (in1.txt) and (in2.txt) that have text in them.
java Cat in1.txt in2.txt out.txt
My code is provided below.
public class Cat {
public static void main(String[] args) {
Out out = new Out(args[args.length -1]);
for(int i = 0; i < args.length -1; i++)
{
In in = new In(args[i]);
String s = in.readAll();
out.println(s);
in.close();
}
out.close();
}
}
cd to the directory where Cat.class is located before you run the java command.

Categories