-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextFile.java
More file actions
42 lines (40 loc) · 792 Bytes
/
TextFile.java
File metadata and controls
42 lines (40 loc) · 792 Bytes
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
package com.example.regex;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class TextFile
{
public static String openFile(String path)
{
File file = new File(path);
if (!file.exists())
return null;
BufferedInputStream in = null;
try
{
in = new BufferedInputStream(new FileInputStream(file));
byte[] bytes = new byte[in.available()];
in.read(bytes);
return new String(bytes);
} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} finally
{
if (in != null)
try
{
in.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
return null;
}
}