Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programmers' lounge. (Programming-related discussions only)
New Posts  All Forums:Forum Nav:

Programmers' lounge. (Programming-related discussions only) - Page 111

post #1101 of 1108
Anyone have any idea why this doesn't work? (Java)

This is in my start method:
Code:
File file = new File ("/resources/UserScores.txt");
OpenFile.openFile(file); //<------------------------------------------ error on this line

This is the OpenFile method being called:
Code:
class OpenFile extends Assignment2 {

    static void openFile(File file) {
        String str;
        FileInputStream myFis=null;
        try {
            myFis = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            System.out.println(e.getMessage());
        }
        BufferedReader myBr=new BufferedReader(new  InputStreamReader(myFis)); //<------------------------------------------ and error on this line

        try {
            Users.clear();
            while ( (str=myBr.readLine()) != null) {

                String [] strs = str.split(",");
                String name = strs[0];
                Integer score = Integer.parseInt(strs[1]);
                Users.add(new User(name, score));
            }
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
        System.out.println(Users.size());
    }
}

The exception I get is this:
\resources\UserScores.txt (The system cannot find the path specified)

This would imply that the path set is wrong but I've targeted other resources in that folder elsewhere in the program without issue ("/resources/18.png" for example).

Any help would be massively, massively appreciated.
Edited by twerk - 6/18/15 at 10:44am
Define
(20 items)
 
XMG P304
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-3770K @ 4.4GHz Gigabyte GA-Z77X-UD5H EVGA GeForce GTX 680 2GB 2x8GB Kingston HyperX Fury @ 2133MHz 
Hard DriveHard DriveCoolingCooling
Samsung 840 Pro 256GB Crucial MX100 512GB Noctua NH-U14S 3x Noctua NF-A14 FLX 
OSMonitorMonitorKeyboard
Windows 7 Professional 64-bit Dell U2713HM Dell U2312HM Ducky Shine 3 Year of the Snake - MX Brown 
PowerCaseMouseMouse Pad
EVGA SuperNOVA G2 750W Fractal Design Define R5 Black Mionix Naos 7000 SteelSeries QcK 
AudioAudioAudioOther
Schiit Modi Schiit Magni beyerdynamic DT 880 Premium 600 ohms TP-LINK Archer T9E  
CPUMotherboardGraphicsRAM
Intel Core i7-4710MQ @ 3.5GHz Intel HM87 Express Chipset Nvidia GTX 860M 2GB Crucial 2x4GB Crucial Ballistix Sport @ 1600MHz 
Hard DriveOSMonitor
Samsung 850 EVO 120GB Microsoft Windows 7 Professional 64-bit  Innolux N133HSE-EA1 
  hide details  
Reply
Define
(20 items)
 
XMG P304
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-3770K @ 4.4GHz Gigabyte GA-Z77X-UD5H EVGA GeForce GTX 680 2GB 2x8GB Kingston HyperX Fury @ 2133MHz 
Hard DriveHard DriveCoolingCooling
Samsung 840 Pro 256GB Crucial MX100 512GB Noctua NH-U14S 3x Noctua NF-A14 FLX 
OSMonitorMonitorKeyboard
Windows 7 Professional 64-bit Dell U2713HM Dell U2312HM Ducky Shine 3 Year of the Snake - MX Brown 
PowerCaseMouseMouse Pad
EVGA SuperNOVA G2 750W Fractal Design Define R5 Black Mionix Naos 7000 SteelSeries QcK 
AudioAudioAudioOther
Schiit Modi Schiit Magni beyerdynamic DT 880 Premium 600 ohms TP-LINK Archer T9E  
CPUMotherboardGraphicsRAM
Intel Core i7-4710MQ @ 3.5GHz Intel HM87 Express Chipset Nvidia GTX 860M 2GB Crucial 2x4GB Crucial Ballistix Sport @ 1600MHz 
Hard DriveOSMonitor
Samsung 850 EVO 120GB Microsoft Windows 7 Professional 64-bit  Innolux N133HSE-EA1 
  hide details  
Reply
post #1102 of 1108
Any reason for the different angle of your slashes in the two paths you posted?
post #1103 of 1108
Quote:
Originally Posted by Plan9 View Post

Any reason for the different angle of your slashes in the two paths you posted?
In my code they are forward slashes "/"

In the exception that pops up they change to back slashes for some reason "\"
Define
(20 items)
 
XMG P304
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-3770K @ 4.4GHz Gigabyte GA-Z77X-UD5H EVGA GeForce GTX 680 2GB 2x8GB Kingston HyperX Fury @ 2133MHz 
Hard DriveHard DriveCoolingCooling
Samsung 840 Pro 256GB Crucial MX100 512GB Noctua NH-U14S 3x Noctua NF-A14 FLX 
OSMonitorMonitorKeyboard
Windows 7 Professional 64-bit Dell U2713HM Dell U2312HM Ducky Shine 3 Year of the Snake - MX Brown 
PowerCaseMouseMouse Pad
EVGA SuperNOVA G2 750W Fractal Design Define R5 Black Mionix Naos 7000 SteelSeries QcK 
AudioAudioAudioOther
Schiit Modi Schiit Magni beyerdynamic DT 880 Premium 600 ohms TP-LINK Archer T9E  
CPUMotherboardGraphicsRAM
Intel Core i7-4710MQ @ 3.5GHz Intel HM87 Express Chipset Nvidia GTX 860M 2GB Crucial 2x4GB Crucial Ballistix Sport @ 1600MHz 
Hard DriveOSMonitor
Samsung 850 EVO 120GB Microsoft Windows 7 Professional 64-bit  Innolux N133HSE-EA1 
  hide details  
Reply
Define
(20 items)
 
XMG P304
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-3770K @ 4.4GHz Gigabyte GA-Z77X-UD5H EVGA GeForce GTX 680 2GB 2x8GB Kingston HyperX Fury @ 2133MHz 
Hard DriveHard DriveCoolingCooling
Samsung 840 Pro 256GB Crucial MX100 512GB Noctua NH-U14S 3x Noctua NF-A14 FLX 
OSMonitorMonitorKeyboard
Windows 7 Professional 64-bit Dell U2713HM Dell U2312HM Ducky Shine 3 Year of the Snake - MX Brown 
PowerCaseMouseMouse Pad
EVGA SuperNOVA G2 750W Fractal Design Define R5 Black Mionix Naos 7000 SteelSeries QcK 
AudioAudioAudioOther
Schiit Modi Schiit Magni beyerdynamic DT 880 Premium 600 ohms TP-LINK Archer T9E  
CPUMotherboardGraphicsRAM
Intel Core i7-4710MQ @ 3.5GHz Intel HM87 Express Chipset Nvidia GTX 860M 2GB Crucial 2x4GB Crucial Ballistix Sport @ 1600MHz 
Hard DriveOSMonitor
Samsung 850 EVO 120GB Microsoft Windows 7 Professional 64-bit  Innolux N133HSE-EA1 
  hide details  
Reply
post #1104 of 1108
Does your file get created and does it have the proper permissions?
Workstation mk I
(15 items)
 
ASUS A73S
(16 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i5-4670k Gigabyte G1.Sniper 5 EVGA GTX 760 4GB ACX (04G-P4-2768-KR) G.Skill Ares 16GB 2133 dual channel kit 
Hard DriveHard DriveCoolingOS
SanDisk 128 GB SSD 2x WD Red 2TB SATA3 Stock Windows 8 
MonitorKeyboardPowerCase
LG Flatron W2343T Dell SK-8135 EVGA Supernova 1300 80 gold Corsair 900D 
MouseMouse PadAudio
Nexus silent mouse Custom handmade Onboard Creative new thingy. Oh where is my 20-... 
CPUMotherboardGraphicsRAM
Core i7 2670qm ASUSTeK K73SD GeForce 610M 8 GB Samsung 
Hard DriveOptical DriveCoolingOS
750 GB Hitachi HTS54somenumbers Matshita DVD-RAM UJ8B0AW Laptop cooling — snakey heatpipe, some heatsink... Windows 8 pro 
MonitorMonitorKeyboardPower
Some 17" 1600×900 glossy panel, not too shabby. LG Flatron W2343T Most keys are perfect square. A few elongated r... The AC/DC adapter makes a high-pitched sighing ... 
CaseMouseMouse PadAudio
Not slim. Nexus silent mouse Custom handmade Built in, some realtek crap. 
CPUMotherboardGraphicsRAM
Pentium® III-S 1.13 GHz Compaq ProLiant ML330 G2 ATI Rage XL/XC 2 GB Kingston 
Hard DriveHard DriveOptical DriveCooling
A couple 500GB SCSI II disks in raid 1. 120GB SCSI II disk HL-DT-ST DVD-RAM Stock. It’s noisy. 
OSPowerCaseAudio
Windows XP Pro SP 3 Some PSU I pulled out from under my bed. Compaq. Very genuine case. Some Legacy audio. 
OtherOther
Realtek RTL8169/8110 Gigabit ethernet NIC AMI MegaIDE raid controller 
  hide details  
Reply
Workstation mk I
(15 items)
 
ASUS A73S
(16 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i5-4670k Gigabyte G1.Sniper 5 EVGA GTX 760 4GB ACX (04G-P4-2768-KR) G.Skill Ares 16GB 2133 dual channel kit 
Hard DriveHard DriveCoolingOS
SanDisk 128 GB SSD 2x WD Red 2TB SATA3 Stock Windows 8 
MonitorKeyboardPowerCase
LG Flatron W2343T Dell SK-8135 EVGA Supernova 1300 80 gold Corsair 900D 
MouseMouse PadAudio
Nexus silent mouse Custom handmade Onboard Creative new thingy. Oh where is my 20-... 
CPUMotherboardGraphicsRAM
Core i7 2670qm ASUSTeK K73SD GeForce 610M 8 GB Samsung 
Hard DriveOptical DriveCoolingOS
750 GB Hitachi HTS54somenumbers Matshita DVD-RAM UJ8B0AW Laptop cooling — snakey heatpipe, some heatsink... Windows 8 pro 
MonitorMonitorKeyboardPower
Some 17" 1600×900 glossy panel, not too shabby. LG Flatron W2343T Most keys are perfect square. A few elongated r... The AC/DC adapter makes a high-pitched sighing ... 
CaseMouseMouse PadAudio
Not slim. Nexus silent mouse Custom handmade Built in, some realtek crap. 
CPUMotherboardGraphicsRAM
Pentium® III-S 1.13 GHz Compaq ProLiant ML330 G2 ATI Rage XL/XC 2 GB Kingston 
Hard DriveHard DriveOptical DriveCooling
A couple 500GB SCSI II disks in raid 1. 120GB SCSI II disk HL-DT-ST DVD-RAM Stock. It’s noisy. 
OSPowerCaseAudio
Windows XP Pro SP 3 Some PSU I pulled out from under my bed. Compaq. Very genuine case. Some Legacy audio. 
OtherOther
Realtek RTL8169/8110 Gigabit ethernet NIC AMI MegaIDE raid controller 
  hide details  
Reply
post #1105 of 1108
Fixed it. For some reason it couldn't be accessed from within the resources folder, which I don't understand because the images could but oh well. I just moved it to the project root and it's now fine.

Thanks!
Define
(20 items)
 
XMG P304
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-3770K @ 4.4GHz Gigabyte GA-Z77X-UD5H EVGA GeForce GTX 680 2GB 2x8GB Kingston HyperX Fury @ 2133MHz 
Hard DriveHard DriveCoolingCooling
Samsung 840 Pro 256GB Crucial MX100 512GB Noctua NH-U14S 3x Noctua NF-A14 FLX 
OSMonitorMonitorKeyboard
Windows 7 Professional 64-bit Dell U2713HM Dell U2312HM Ducky Shine 3 Year of the Snake - MX Brown 
PowerCaseMouseMouse Pad
EVGA SuperNOVA G2 750W Fractal Design Define R5 Black Mionix Naos 7000 SteelSeries QcK 
AudioAudioAudioOther
Schiit Modi Schiit Magni beyerdynamic DT 880 Premium 600 ohms TP-LINK Archer T9E  
CPUMotherboardGraphicsRAM
Intel Core i7-4710MQ @ 3.5GHz Intel HM87 Express Chipset Nvidia GTX 860M 2GB Crucial 2x4GB Crucial Ballistix Sport @ 1600MHz 
Hard DriveOSMonitor
Samsung 850 EVO 120GB Microsoft Windows 7 Professional 64-bit  Innolux N133HSE-EA1 
  hide details  
Reply
Define
(20 items)
 
XMG P304
(7 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-3770K @ 4.4GHz Gigabyte GA-Z77X-UD5H EVGA GeForce GTX 680 2GB 2x8GB Kingston HyperX Fury @ 2133MHz 
Hard DriveHard DriveCoolingCooling
Samsung 840 Pro 256GB Crucial MX100 512GB Noctua NH-U14S 3x Noctua NF-A14 FLX 
OSMonitorMonitorKeyboard
Windows 7 Professional 64-bit Dell U2713HM Dell U2312HM Ducky Shine 3 Year of the Snake - MX Brown 
PowerCaseMouseMouse Pad
EVGA SuperNOVA G2 750W Fractal Design Define R5 Black Mionix Naos 7000 SteelSeries QcK 
AudioAudioAudioOther
Schiit Modi Schiit Magni beyerdynamic DT 880 Premium 600 ohms TP-LINK Archer T9E  
CPUMotherboardGraphicsRAM
Intel Core i7-4710MQ @ 3.5GHz Intel HM87 Express Chipset Nvidia GTX 860M 2GB Crucial 2x4GB Crucial Ballistix Sport @ 1600MHz 
Hard DriveOSMonitor
Samsung 850 EVO 120GB Microsoft Windows 7 Professional 64-bit  Innolux N133HSE-EA1 
  hide details  
Reply
post #1106 of 1108
Quote:
Originally Posted by twerk View Post

Anyone have any idea why this doesn't work? (Java)

This is in my start method:
Code:
File file = new File ("/resources/UserScores.txt");
OpenFile.openFile(file); //<------------------------------------------ error on this line

Did you try this:
Code:
File file = new File ("resources/UserScores.txt");
OpenFile.openFile(file); //<------------------------------------------ error on this line

You seem to be using Windows, so I am not entirely certain, but at least on Linux etc OS'es that would be an absolute path rather than relative (hence the leading slash), so it might refer to something like C:\resources\UserScores.txt instead of C:\something\morething\project123\resources\UserScore.txt on your Windows.

Also, for the reason the slashes changing to backslashes: slash ( / ) is the appropriate notation to use in the code, because the JVM will automatically translate that to environment specific directory separator, which is backslash on Windows.
Doomsday Device
(21 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i5-3550 Intel DZ77RE-75K Geforce GTX 980 Geforce GTX 670 
RAMHard DriveHard DriveOptical Drive
Kingston HyperX Black 32GB (4x8GB) WD Caviar Black (SATA-III) OCZ Vertex 4 TSSTcorp DVD RW 
CoolingOSOSMonitor
Scythe Ninja 3 Xubuntu 13.04 Windows 7 Samsung Syncmaster 2494HS 
MonitorMonitorMonitorKeyboard
Dell E228WFP Dell E228WFP Fujitsu Siemens SCENICVIEW A19-3A Ducky Shine 2 
PowerCaseMouseAudio
Nexus RX-8500 BitFenix Shinobi XL Steelseries Sensei [RAW] Integrated 10 channel HD audio 
Other
Dual Gigabit LAN subsystems using the Intel® 82... 
  hide details  
Reply
Doomsday Device
(21 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i5-3550 Intel DZ77RE-75K Geforce GTX 980 Geforce GTX 670 
RAMHard DriveHard DriveOptical Drive
Kingston HyperX Black 32GB (4x8GB) WD Caviar Black (SATA-III) OCZ Vertex 4 TSSTcorp DVD RW 
CoolingOSOSMonitor
Scythe Ninja 3 Xubuntu 13.04 Windows 7 Samsung Syncmaster 2494HS 
MonitorMonitorMonitorKeyboard
Dell E228WFP Dell E228WFP Fujitsu Siemens SCENICVIEW A19-3A Ducky Shine 2 
PowerCaseMouseAudio
Nexus RX-8500 BitFenix Shinobi XL Steelseries Sensei [RAW] Integrated 10 channel HD audio 
Other
Dual Gigabit LAN subsystems using the Intel® 82... 
  hide details  
Reply
post #1107 of 1108
I've just finished the Introduction to Javascript on Khan Academy and I'm wondering where to go next.

Which would be a productive programming language to learn for a non-programmer, just for fun / as a brain teaser / as something to spice up the CV?
post #1108 of 1108
Quote:
Originally Posted by Six-Strings View Post

I've just finished the Introduction to Javascript on Khan Academy and I'm wondering where to go next.

Which would be a productive programming language to learn for a non-programmer, just for fun / as a brain teaser / as something to spice up the CV?

Probably Python.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programmers' lounge. (Programming-related discussions only)