Beginner question - Can't read nor write a file using NetBean...

Hi ,
I'm a beginner java programmer, I got trouble when it comes to read or write a file program..
I tried 3 programs and all of them can't read the file I want to read, eventhought I have put the txt file in the same folder with my source code.
here is the source code I got from some site
import java.io.*;
class FileReadTest {
public static void main (String[] args) {
     FileReadTest f = new FileReadTest();
f.readMyFile();
void readMyFile() {
DataInputStream dis = null;
String record = null;
int recCount = 0;
try {
File f = new File("mydata.txt");
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
while ( (record=dis.readLine()) != null ) {
recCount++;
System.out.println(recCount + ": " + record);
} catch (IOException e) {
// catch io errors from FileInputStream or readLine()
System.out.println("Uh oh, got an IOException error! " + e.getMessage());
} finally {
// if the file opened okay, make sure we close it
if (dis != null) {
     try {
dis.close();
     } catch (IOException ioe) {
I also have tried another from book , both of them give the same result, can't read the file...
Please help me with this...
Thank you very much

To start with use the full path to the file
i.e. File f = new File("c:\\the\\full\\path\\to\\your\\file\\mydata.txt"); // Assumes a Windows platform using the C drive
Then check to make sure you fiel exists e.g. System.out.println("File exists = " + f.exists());
You can even test to see if the file is readable but since you created the file this porbably is not required.

Similar Messages

  • Can't read or write some files, internet is failing, youtube won't load, software I tried to install was in Slovenian, not dutch or english like in my systempreferences settings, pictures and files won't preview with spacebar, etc. Malware?

    Specs:
    iMac 10.8.5
    3,4 GHz Intel Core i7
    32 GB 1600 MHz DDR3
    Can't read or write some files, internet is failing, youtube won't load, security software I tried to install was in Slovenian, not dutch or english like in my systempreferences settings, pictures and files won't preview with spacebar and are randomly corrupted, when I entered something in the Youtube searchbar (when it was still working) it send me to a site with sexadds.
    I tried restart my iMac and when I was logged back in, my dock preferences were reset.
    Also tried to download some security software to check my Mac for malware, but when I did, I tried several, I got a notification that said something like 'dumpfiles (don't know if this is the right translation...) damaged'.
    I'm taking screenshots from all the weird notifications I get and even three quarters off the screenshots I took in the last three hours are already unreadable.
    It started this morning when I tried opening a Premiere Pro file on which I worked the night before.
    When I tried opening it, it said the file was damaged and could not be openend.
    I tried opening it with AE or importing the file in a new project but nothing helped.
    When I tried looking for autosaves, this is the really weird part, there were none.
    Even though there are autosaves from my other projects, this one was completely gone.
    It looked like the day before never happened on my computer.
    Also when I openend Premiere all the recent projects had been wiped.
    So at first I thought it was a Premiere Pro failure.
    But than, later on the day, I tried loading some RAW files from my compact flash card.
    This is where I would get an error (error -36) which said some data cannot be read or written.
    I tried importing the files with a view different technics, from dragging to importing via Lightroom and I succeeded with Image Browser.
    But when I tried moving the files to an other folder the same error occurred.
    While dealing with this issue I wanted to put on some soothing music on youtube.
    This is when the next weird thing occurred: youtube wasn't completely loading in Chrome. I refreshed a view times, checked the internet connection and still no difference.
    When I tried in Safari it did work but when I clicked enter on the searchbar in Youtube, a page with sexadds appeared (I didn't install AdBlock in Safari...).
    I read about this 'phishing' where you are redirected to a site were a possible malware installment can take place...
    I don't know if it's connected to any of the problems I've been having but I just never experienced this on a mac, I have been a Mac user for 10 years now.
    On top of it all, internet started working worse and worse and now it's not even working at all. I had to fill in the password over and over, normally it remembers.
    Just like my system preferences, all the preferences I had with Chrome where also reset.
    Also somewhere in between I got this notification: Mac OS X must restore library to run programs. Type your password to allow.
    To me this is all very weird and suspicious. I have clearly no idea what's going on. Could this be another sort of trojan horse or malware?
    Some background info which could be helpful for solving this mystery:
    two months ago the one year old Fusion Drive in my iMac just broke out of nowhere.
    I got it replaced by a qualified apple repair store.
    When I got my computer back, all the files where gone.
    I got on the internet without AdBlock installed yet.
    A game or whatever it was, can't clearly remember, got installed by accident.
    I deleted it immediately.
    Only two weeks later, I couldn't log in to my account. It didn't recognize my password and username. 
    So I brought my mac back to the store.
    Here the repair guy said it was a minor thing and he just needed to reconnect my account. He also mentioned he found a downloaded game name Sparta and it probably had something to do with the error.
    I asked him; could it be a virus? He replied no way.
    I don't know why I couldn't be a virus, just because it's a mac doesn't mean it cannot be done.
    So today I tried installing anti virus software (such as avast- was in a weird language looked like slovenian, clamxav - was in slovenian) but I couldn't install them.
    PLEASE help me! I don't know what to do anymore, I work fulltime and I need my computer, I have no time to bring it in for repair, are there other perhaps easier ways?
    Could this be the work of a virus or a malware? Or is it a disk permissions issue?

    It sounds like you may have multiple problems, but none of them are likely to be caused by malware.
    First, the internet-related issues may be related to adware or a network compromise. I tend to lean more towards the latter, based on your description of the problem. See:
    http://www.adwaremedic.com/kb/baddns.php
    http://www.adwaremedic.com/kb/hackedrouter.php
    If investigation shows that this is not a network-specific issue, then it's probably adware. See my Adware Removal Guide for help finding and removing it. Note that you mention AdBlock as if it should have prevented this, but it's important to understand that ad blockers do not protect you against adware in any way. Neither would any kind of anti-virus software, which often doesn't detect adware.
    As for the other issues, it sounds like you've got some serious corruption. I would be inclined to say it sounds like a failing drive, except it sounds like you just got it replaced. How did you get all your files back after the new drive was installed?
    (Fair disclosure: I may receive compensation from links to my sites, TheSafeMac.com and AdwareMedic.com, in the form of buttons allowing for donations. Donations are not required to use my site or software.)

  • Ipod Touch message "itunes can neither read nor write to "my Name" disk.

    While syncing my Touch on I- Tunes, everything stopped and the message was "can neither read or write to B-----J-----"s ipod disk. I was on the phone for hours with Apple support, sent the Touch back twice to no avail. Finally found a newly acquired song from I-tunes stopped the sync in its' tracks and could not be recovered from. Has anyone else had this problem?

    I have a second gen which I received today as a replacement from Apple as they thought that might solve my problem. I found a recently acquired song, David Gilmore's "Where We Start " caused the crash. I did a manual load of the touch after a restore of it"s software and tunes. I watched the computer screen as I updated several songs at a time. I recreated the problem three times so I am confident I know what caused it but the only way I know around it is the slow process of a manual update. I have reported it to Itunes because this has taken me two weeks to figure out.

  • Can v read a client text file using SQL*plus??

    We have a requirement like this: We need to read a text file to find spelling mistakes. Problem is the file has to be always moved to the DB machine, which is a Linux box and then run a stored procedure which uses UTL_FILE. Now in order to show the spelling mistakes of the file the user will have to again copy the file with the spelling mistakses (output file) from Linux to Windows.
    Is there a way to do it using SQL*Plus, where the text file is in the client machine???? Then users don't have to copy the file to and from the Linux box.

    SQL*Plus is a client software and whatever code you write using SQL*Plus, it ultimately run on the server. So the answers to your question is "no".

  • External HDD Error -36 ("can't read or write the file")

    hi,
    just got my WD Mybook 500GB. I reformated the HD to Mac OS Extended (journaled), 1 partition - and wanted to copy my files onto it. after copying 126 GB, the disk doesn't except any more files (any type) - with prompting me with this message: "File couldn't be read or written" Error -36.
    does anyone know why?
    thx, cmu

    Sometimes removing this file has fixed writing issues and reading issues of MyBook drives:
    Macintosh HD -> Library -> Launch Daemons called com.WD.WDDriveServices.plist
    Restart and see if it does.
    If not, sounds like the drive case in question has an old IDE bus. I'd return it to the place you bought it, or ask Western Digital to apply a firmware update to it so it can write past 128 GB. This article seems to be relevant to your problem:
    http://docs.info.apple.com/article.html?artnum=86178
    A -36 error is an input/output error.

  • ITunes can't read or write to iPod -- won't sync

    Classic 30 Gb iPod approx 1 yr old, Windows XP Pro, iTunes 7.5. I added some new trax to iTunes to make total approx 5800 trax, 18 Gb. When I attach the iPod it will load approx 130 trax, 380 Mb, then get msg that iTunes can neither read nor write to the hard disk. The loaded trax will play. I have done the 5 Rs many times, sent the iPod to Apple twice, deleted iTunes many times, deleted the iTunes library and partially reloaded my CDs, all to no avail. I am convinced that I have an iTunes prob because a) Apple can't find a prob and b) I can load my wife's library of approx 1000 trax, using her computer w 7.5

    hi, im also having a similar sort of problem. previous generation iPod video 80Gb version, windows vista 32bit and itunes 7.5(although the problem also occurred with the last 7.4 update).currently the iPod is empty, and out of the 9364 songs (50.01 Gb) in my itunes library, less than 100mb will be synced to my ipod before the sync simply cuts out, like it had completed the sync normally. I have taken the ipod in to an apple store and it synced perfectly with a mac. I have also tried removing and re-installing itunes, even deleted the preferences and other app data that normally gets left in the computer, and i also tried restoring the ipod to factory settings several times to no avail... oh, and i also tried using different cables to connect the ipod, incase the cable was loose, but that didnt work either.

  • "Can't Read Or Write to disk" Video Won't Transfer To Ipod

    I have transfered videos to my ipod in the past but I have two tv shows from the Itunes story that won't transfer.
    They are in the correct mpeg 4 whatever format. My itunes is the most resent version, but for some reason I keep getting the same error.
    "Cannot Read Or Write To Disk".
    HELP??!!
      Windows XP  

    I've got this problem too. My 5g iPod 30gig syncs after about 3 minutes with iTunes then after loading songs and videos after 10 minutes i get the same message your getting - "Can't Read Or Write to disk". I think theres some kind of USB2 conflict or something. All my other USB devices work fine. All my drivers and software is up-to-date.

  • Help. External Hard drive "In use," can't read or write

    I was copying files from my iMac desktop to an external drive that I have been using for years. Suddenly, the drive didn't complete the operation. Now I can't read or write. Permissions seem fine. Tried to verify and repair in disc utility, but got a "unable to unmount disc" message. Then drive has to be force ejected. Rebooting is stalled until I unplug the drive. Can't even create a disc image of it. Tried booting in safe mode to do Disc Utility - no dice. Any help? Desparate.
    Douglas

    Oh... in use... see if Spotlight or Time Machine is trying to use it.
    Open Console in Applications>Utilities & see if there are any clues or repeating messages when this happens.

  • Fstream can't read or write files 4GB even with -m64?

    Using C++-style streams, I have been unable to read or write files >4GB. For example, when writing 5GB in one go, I get only 1GB. The header for write uses the type streamsize for the size parameter, and according to sizeof, streamsize is 8 bytes (when using -m64). Looking at the assembly for a simple testcase, I verified that size parameter was not truncated before calling the write function.
    What makes this interesting is that I can read or write large files if I do it in the C-style (fopen, fwrite, fclose) or if I use the C++ functions and manually do it in 1GB blocks. I tried the instructions for LFS, but they didn't work and it seems like it shouldn't since this is C++ and I am building a 64-bit app. I have observed this with solaris studio 12.3 and 12.4.
    Is this a bug or am I missing a compiler flag?
    A simple testcase to expose this:
    #include <iostream>
    #include <fstream>
    #include <stdio.h>
    using namespace std;
    int main() {
      streamsize goal_size = ((int64_t) 1<<32) + ((int64_t) 1<<30);
      cout << goal_size << endl;
      char* data = new char[goal_size];
      fill(data,data+goal_size,'c');
      FILE* f = fopen("classic.data","w");
      fwrite(data,1,goal_size,f);
      fclose(f);
      fstream file("stream.data", std::ios::out | std::ios::binary);
      file.write(data,goal_size);
      file.close();

    Eh... sorry, didnt read the source close enough
    I can reproduce your misbehavior when compiling "by default" (with default -library=Cstd).
    It fails somewhat differently with Apache STL (-library=stdcxx4), which is kinda the modern version of Cstd.
    It works fine when compiling with -library=stlport4, or -library=stdcpp (-std=c++11).
    Looks like it is a deficiency of those particular STLs.
    regards,
      Fedor.

  • Can't read or Write to disc

    Using Windows XP I get an error (can't read or write to disc) when trying to sync my Ipod. It also says not enough room on disc at times.I was able to do this before. But it now fails. I sent the Ipod in for repair, it was stated that it needed disc repair. So I had it done. When I received it back and tried to use it I got the same errors. I was all ready to call the repair company and complain, but decided to try it on my computer using Vista. Everything works fine there. But now on the one using Xp. Anyone have any ideas on what might be the problem?

    Hi, did you ever have this issue resolved? I am now having the same problem. I was told that they hadn't a clue to what was going on and to make an appt to bring my laptop, external hard drive AND my iPhone in order to see what the problem is. I'd really like to know what you found out. I'm a home-school teacher and my phone is everything!
    Thank you

  • Can't read or write from iPod when it syncs with a big library

    When I try to sync with my 50Gb size library in the iTunes installed on my iBook G4 (10.4.11), it appears "can't read or write from the ipod", in the middle of the synchronization. It starts to do the job very well, but when it has done only 6 or 8 Gb, the process got slower until it appears such message. I have iTunes 7.6 and ipod firmware 1.1. I have tried on Windows and Mac plattforms, trying all the combinations (Mac and/or Win formats) and the trouble persists. The device has only two weeks of use, and it was working perfectly until now. The problem it is the same if I do it manually (no automatic sync). I am not sure if the problem is defective hardware, does anybody have any idea or have similar problem? Thanks.

    Thanks a lot for your answer. The idea of an increasing autoplaylist it is pretty good. I did it, in 5 Gb steps, and in the thrid step (10 Gb done), when it only has copied almost one Gb, the error message pop up again. Before the message appears, iTunes become slower and slower copyng each song until it stops in one song, and after a while, message appears. After, the system come down, almost blocked, and it takes a long until I can mount the ipod again. Of course, ipod restarts automatically and the songs copied in the last step are not there. I was taking care in every moment of the process, avoiding to leave the system suspend alone (and also turning off all the saving energy options). I am now pretty sure that the problem is on the device. Anyway, thank you very much for your valuable ideas.

  • Since I upgrade to Lion OS my optical drive stop working can't read or write at all I did what I could to fix it but still not working , any help please

    Since I upgrade to Lion OS my optical drive stop working can't read or write at all I did what I could to fix it but still not working , any help please

    It sounds like you may have multiple problems, but none of them are likely to be caused by malware.
    First, the internet-related issues may be related to adware or a network compromise. I tend to lean more towards the latter, based on your description of the problem. See:
    http://www.adwaremedic.com/kb/baddns.php
    http://www.adwaremedic.com/kb/hackedrouter.php
    If investigation shows that this is not a network-specific issue, then it's probably adware. See my Adware Removal Guide for help finding and removing it. Note that you mention AdBlock as if it should have prevented this, but it's important to understand that ad blockers do not protect you against adware in any way. Neither would any kind of anti-virus software, which often doesn't detect adware.
    As for the other issues, it sounds like you've got some serious corruption. I would be inclined to say it sounds like a failing drive, except it sounds like you just got it replaced. How did you get all your files back after the new drive was installed?
    (Fair disclosure: I may receive compensation from links to my sites, TheSafeMac.com and AdwareMedic.com, in the form of buttons allowing for donations. Donations are not required to use my site or software.)

  • Can not read or write to mac hard drive error

    When attempting to transfer music files from an external usb harddrive formatted in windows into Itunes, I can only successfully import a small fraction of the music, and then its stops with a error, that the Mac HD can not read or write files.

    It's possible the file names have some 'funky' characters in them that the Mac doesn't like ?
    What format is the external drive ?

  • How can I read and write text in rings that are inside an array?

    Hello All!!!
    How can I read and write text in rings that are inside an array?
    Regards and thanks in advance.

    Use a Property Node linked to the Ring inside the array.
    Of course, all elements in the array will have the same text values.
    B-)
    Message Edited by LabViewGuruWannabe on 12-13-2007 09:47 AM
    Message Edited by LabViewGuruWannabe on 12-13-2007 09:48 AM
    Message Edited by LabViewGuruWannabe on 12-13-2007 09:49 AM
    Attachments:
    Strings-BD.PNG ‏17 KB
    Strings-FP1.PNG ‏23 KB

  • I'm trying to share folder between users on a single mac.  I put the folder in "shared," set permissions so other user can read and write, enabled file sharing, but can't find the folder on the second user's account.  Any help?

    I'm trying to share a folder between users on a single mac.  I want both users to be able to read and write so the folder stays current on both accounts.  I put the folder in "shared," set permissions on folder so other user can read and write, enabled file sharing, but can't find the folder on the second user's account.  Any help?

    Did you log out of one account and into the other or just used Fast user switching?
    Is the permissions set to anyone?
    When you move data to teh Shared folder is it copied or just moved?
    If copied then it's not a folder both can access, just a way station like a USB thumb drive that things are coped too and off of likely.
    You can run this #5 on each user account to reset the user permissions once they are taken back out of the Shared folder
    Step by Step to fix your Mac

Maybe you are looking for