-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenFile2.java
41 lines (32 loc) · 908 Bytes
/
OpenFile2.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
package Cryptography;
import java.io.File;
//import java.io.FileNotFoundException;
import java.util.Scanner;
import javax.swing.JFileChooser;
public class OpenFile2 {
//JFileChooser filechooser=new JFileChooser();
//StringBuilder sb=new StringBuilder();
public static String pickFile() throws Exception
{
JFileChooser filechooser=new JFileChooser();
StringBuilder sb=new StringBuilder();
String Data="";
if(filechooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
{
File file = filechooser.getSelectedFile(); //get the file
Scanner input= new Scanner(file);
while(input.hasNext())
{
//Data+=input.nextLine();
//System.out.println(input.nextLine());
sb.append(input.nextLine());
sb.append("");
}
input.close();
}
else{
sb.append("No file was selected");
}
return sb.toString();
}
}