Hello this program is supposed to read the data of a specified .txt file which it does then it promts you to pick a specfic line of data from that .txt file it compiles fine but will not write data on screen of selected data
import java.nio.file.*; import java.io.*; import java.nio.file.attribute.*; import static java.nio.file.StandardOpenOption.*; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.Scanner; public class ReadStateFile { public static void main(String[] args) { Scanner kb = new Scanner(System.in); String fileName; System.out.print("Enter name of file to use >> "); fileName = kb.nextLine(); fileName = fileName; Path file = Paths.get(fileName); final String ID_FORMAT = "000"; final String NAME_FORMAT = " "; final int NAME_LENGTH = NAME_FORMAT.length(); final String HOME_STATE = "WI"; final String BALANCE_FORMAT = "0000.00"; String delimiter = ","; String s = ID_FORMAT + delimiter + NAME_FORMAT + delimiter + HOME_STATE + delimiter + BALANCE_FORMAT + System.getProperty("line.separator"); final int RECSIZE = s.length(); byte data[] = s.getBytes(); final String EMPTY_ACCT = "000"; String[] array = new String[4]; double balance; double total = 0; try { BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class); System.out.println("\nAttributes of the file:"); System.out.println("Creation time " + attr.creationTime()); System.out.println("Size " + attr.size()); } catch(IOException e) { System.out.println("IO Exception"); } try { InputStream iStream = Files.newInputStream(file, READ); BufferedReader reader = new BufferedReader(new InputStreamReader(iStream)); System.out.println("\nAll non-default records:\n"); s = reader.readLine(); while(s != null) { array = s.split(delimiter); if(!array[0].equals(EMPTY_ACCT)) { balance = Double.parseDouble(array[3]); System.out.println("ID #" + array[0] + " " + array[1] + array [2] + " $" + array[3]); total += balance; } s = reader.readLine(); } System.out.println("Total of all balances is $" + total); reader.close(); } catch(Exception e) { System.out.println("Message: " + e); } try { FileChannel fc = (FileChannel)Files.newByteChannel(file, READ, WRITE); ByteBuffer buffer = ByteBuffer.wrap(data); int findAcct; System.out.print("\nEnter acount to seek >> "); findAcct = kb.nextInt(); fc.position(findAcct * RECSIZE); fc.read(buffer); s = new String(data); System.out.println("Desired record: " + s); } catch(Exception e) { System.out.println("Message: " + e); } } }
first request looks like this in jGRASP
Enter name of file to use >> InStateCusts.txt
Attributes of the file:
Creation time 2012-11-10T18:57:35.21Z
Size 32000
All non-default records:
ID #101 Franklin WI $1034.38
ID #104 Samuels WI $0100.99
Total of all balances is $1135.37
Enter acount to seek >> 101
\\ heres where it goes wrong its supposed to repeat the requested data and i get
Desired record: ,WI,0000.00
00
any help would be appericated!