forked from jainabhi1/search-box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.java
65 lines (63 loc) · 1.51 KB
/
test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package hello;
import java.io.*;
import java.util.*;
import org.apache.commons.exec.*;
import java.nio.file.*;
public class test {
public static void main(String [] args) throws IOException,InterruptedException
{
HashMap<String,Set<String> > hm=new HashMap<>();
trie t=new trie();
try
{
String line = "/bin/sh /home/abhishek/try.sh";
CommandLine commandLine = CommandLine.parse(line);
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
int exitValue = executor.execute(commandLine);
// System.out.println(exitValue);
}
catch(Exception e)
{
//System.out.println("hello");
}
File file=new File("/home/abhishek/workspace/hello/hello2.txt");
String encoding ="UTF-8";
BufferedReader reader=new BufferedReader(new InputStreamReader(
new FileInputStream (file), encoding));
String line="";
while((line=reader.readLine())!=null)
{
//System.out.println(line);
Path p = Paths.get(line);
String r=p.getFileName().toString();
t.add(r);
if(hm.get(r)==null)
{
hm.put(r, new HashSet<>());
}
hm.get(r).add(line);
}
reader.close();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
ArrayList<String> As=t.prefix(s);
if(As.isEmpty())
System.out.println("no file found");
else
{
for(int i=0;i<As.size();i++)
{
String r=As.get(i);
if(hm.get(r)!=null)
{
Set<String> boo=hm.get(r);
for(String ss:boo)
{
System.out.println(ss);
}
}
}
}
}
}