Read line with Scanner

This code reads the file line by line. public static void readFileByLine(String fileName) { try { File file = new File(fileName); Scanner scanner = new Scanner(file); while (scanner.hasNext()) { System.out.println(scanner.next()); } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } You can also set a delimiter as a line separator and then perform the same. … Read more

Bash variable expansion on tab complete

Found the bug report, please register (if not already registered) and add yourself to the ‘people affected’ list, I just did: https://bugs.launchpad.net/ubuntu/+source/bash/+bug/778627 Workarounds Try enabling direxpand or cdable_vars: shopt -s direxpand # or shopt -s cdable_vars Apparently EscTab might be a workaround: I haven’t found a proper solution to this, but there’s a workaround. The … Read more

Undo a file readline() operation so file-pointer is back in original state

You have to remember the position by calling file.tell() before the readline and then calling file.seek() to rewind. Something like: fp = open(‘myfile’) last_pos = fp.tell() line = fp.readline() while line != ”: if line == ‘SPECIAL’: fp.seek(last_pos) other_function(fp) break last_pos = fp.tell() line = fp.readline() I can’t recall if it is safe to call … Read more

MSysGit Bash – how to enable Ctrl+Left / Right arrows?

At your Bash prompt, press Ctrl–v Ctrl–Left-Arrow and Ctrl–v Ctrl–Right-Arrow and make note of the output. You should see something like: ^[OD and ^[OC or similar. Add the following lines to your ~/.inputrc: “\eOC”: forward-word “\eOD”: backward-word where you will substitute \e for escape (^[) and the rest of the characters you got (OD, OC … Read more

How to use readline() method in Java?

I advise you to go with Scanner instead of DataInputStream. Scanner is specifically designed for this purpose and introduced in Java 5. See the following links to know how to use Scanner. Java Documentation Java Tutorial Example Scanner s = new Scanner(System.in); System.out.println(s.nextInt()); System.out.println(s.nextInt()); System.out.println(s.next()); System.out.println(s.next());

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)