MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / openAsString

Method openAsString

ij/src/main/java/ij/IJ.java:2335–2364  ·  view source on GitHub ↗

Opens a text file as a string. Displays a file open dialog if path is null or blank. Returns null if the user cancels the file open dialog. If there is an error, returns a message in the form "Error: message".

(String path)

Source from the content-addressed store, hash-verified

2333 the file open dialog. If there is an error, returns a
2334 message in the form "Error: message". */
2335 public static String openAsString(String path) {
2336 if (path==null || path.equals("")) {
2337 OpenDialog od = new OpenDialog("Open Text File", "");
2338 String directory = od.getDirectory();
2339 String name = od.getFileName();
2340 if (name==null) return null;
2341 path = directory + name;
2342 }
2343 String str = "";
2344 File file = new File(path);
2345 if (!file.exists())
2346 return "Error: file not found";
2347 try {
2348 StringBuffer sb = new StringBuffer(5000);
2349 BufferedReader r = new BufferedReader(new FileReader(file));
2350 while (true) {
2351 String s=r.readLine();
2352 if (s==null)
2353 break;
2354 else
2355 sb.append(s+"\n");
2356 }
2357 r.close();
2358 str = new String(sb);
2359 }
2360 catch (Exception e) {
2361 str = "Error: "+e.getMessage();
2362 }
2363 return str;
2364 }
2365
2366 public static ByteBuffer openAsByteBuffer(String path) {
2367 if (path==null || path.equals("")) {

Callers 11

openAsStringMethod · 0.95
runMethod · 0.95
openMethod · 0.95
getStartupMacroMethod · 0.95
runMethod · 0.95
openMethod · 0.95
doIncludeMethod · 0.95
openMethod · 0.95
actionPerformedMethod · 0.95
getMacroMethod · 0.95
installToolsetToolMethod · 0.95

Calls 8

getDirectoryMethod · 0.95
getFileNameMethod · 0.95
appendMethod · 0.65
closeMethod · 0.65
equalsMethod · 0.45
existsMethod · 0.45
readLineMethod · 0.45
getMessageMethod · 0.45

Tested by

no test coverage detected