473,800 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having trouble writing to a file

11 New Member
Hey all

I have been working on a project which allows me to write to a file and retrieve from that file, but i having trouble with it

These are my inputs:
private int flightno;
private int sourceairportco de;
private int destinationaipo rtcode;
private String takeofftime;
private String landingtime;

These are variables at the top declared
ObjectOutputStr eam output;
ObjectInputStre am input;

i have this in my code

File file = new File(System.get Property("user. dir") + "/data/flights.txt");
(not sure if this is the problem maybe its not writing to the correct place, i have created the data folder with an empty flights.txt file in it)


and here is what aint working

private void btnaddMousePres sed(java.awt.ev ent.MouseEvent evt) {
FlightRecord record;

try{

record = new FlightRecord(

Integer.parseIn t(txtflightno.g etText()),

Integer.parseIn t(txtsource.get Text()),

Integer.parseIn t(txtdestinatio n.getText()),

txttakeoff.getT ext(),

txtlanding.getT ext());

output.writeObj ect(record);

}

catch (Exception e){
JOptionPane.sho wMessageDialog( this, "Something wrong!", "Error",JOption Pane.ERROR_MESS AGE );
}


Any help would be great.
Aug 27 '07 #1
12 1937
Nepomuk
3,112 Recognized Expert Specialist
Are you using Windows? If so, one mistake (maybe not the only, but certainly one, which would cause problems) is here:
File file = new File(System.get Property("user. dir") + "/data/flights.txt");
The File seperator under Windows is \ (System.getProp erty("file.sepa rator") or File.seperator) . You should use those two anyway, to provide independency from the OS.
If you don't want to use either of those, use:
Expand|Select|Wrap|Line Numbers
  1. File file = new File(System.getProperty("user.dir") + "\\data\\flights.txt");
Aug 27 '07 #2
r035198x
13,262 MVP
1.) Please use code tags when posting code
2.) I'm not sure I get the exact problem you're getting but this might help.
Aug 27 '07 #3
Fozzi
11 New Member
Hmm messed about with the file seperator stuff didnt seem to change anything, got to be a problem somewhere else.
Aug 27 '07 #4
r035198x
13,262 MVP
Hmm messed about with the file seperator stuff didnt seem to change anything, got to be a problem somewhere else.
Could you post the full stacktrace or error message that you're getting?
Aug 27 '07 #5
Fozzi
11 New Member
Im using netbeans to do it, and the try and catch blocks just say somethings wrong when i try and add the info to the file,. not sure where i can find the full error message report
Aug 27 '07 #6
r035198x
13,262 MVP
Im using netbeans to do it, and the try and catch blocks just say somethings wrong when i try and add the info to the file,. not sure where i can find the full error message report
In the catch block just put
Expand|Select|Wrap|Line Numbers
  1. e.printStackTrace();
replace e with your exception variable name and then watch the console window when running it to see the fireworks.
Aug 27 '07 #7
Fozzi
11 New Member
think its something to do with the directopry of the file its being saved to

File file = new File(System.get Property("user. dir") + "\\data\\flight s.txt");

my flights file is premade and is in

C:\Documents and Settings\Fozzi\ assignment7\dat a\flights.txt

is that the correct path? maybe i need to add something extra
Aug 27 '07 #8
r035198x
13,262 MVP
think its something to do with the directopry of the file its being saved to

File file = new File(System.get Property("user. dir") + "\\data\\flight s.txt");

my flights file is premade and is in

C:\Documents and Settings\Fozzi\ assignment7\dat a\flights.txt

is that the correct path? maybe i need to add something extra
What's your current working directory?
You can also print the value of
System.getPrope rty("user.dir") + "\\data\\flight s.txt" to the console to see if it's path you intended.
Aug 27 '07 #9
Fozzi
11 New Member
My current working directory is

C:\Documents and Settings\Fozzi\ assignment7

assignment 7 being the main project folder that i am working from there are several folders within and i created the data folder with the txt file in it, in assignment 7
Aug 27 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
4967
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
12
2135
by: Winbatch | last post by:
Hi, I'm trying to learn multithreading and it doesn't seem to be working for me. I have a feeling it has to do with the fact that I'm writing to files rather than to printf, but maybe not. Basically, I wanted to see if it would be faster to write to 4 files at the same time (parallel) rather than 4 in a row (serially). however, when my multithreaded code executes, it seems to do them in order anyway (I expected to see Starting/Ending all...
3
1405
by: rdh | last post by:
I'm using List<> to store a class of positions. Position are basically latitude and longitudes (doubles). the line is something like List<position> P = new List<position>(); Then I start adding to the List. P.add(Positions);
9
7336
suzee_q00
by: suzee_q00 | last post by:
I will admit that lots of times the obvious eludes me and this is most likely one of those times but if anyone has any ideas on what I can do to make this code work, I would greatly appreciate it. Here's the code: while ( ( fgets ( buf, BUFLEN, fin ) ) != NULL ) /* pulls a line from "fin" up to the length of BUFLEN and stores it in "buf" */ { rmNl ( buf ); /* remove new line */ if ( !lineWithBlanks ( buf ) ) { for (i = 0; buf !=...
2
2545
by: spidey12345 | last post by:
what i need this program to do is to read paragraphs like "st blah blh test ere se sit blha eere w" and then it will reformat to "st blah blh test ere se sit blha eere w" ....
1
2046
by: John Wright | last post by:
I am running a console application that connects to an Access database (8 million rows) and converts it to a text file and then cleans and compacts the database. When it runs I get the following error: The CLR has been unable to transition from COM context 0x1a2008 to COM context 0x1a2178 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long...
0
1722
grassh0pp3r
by: grassh0pp3r | last post by:
Hello, I'm trying to make a very simple comments page on my site using PHP and am having problems somewhere. I am very new to PHP. I was able to create one that works with comments appended, but I want the latest comment to be on top, and that's where I'm running into trouble. Since I know very little about PHP, I thought I was clever in what I came up with. I think it can work if I get the coding right. Let me know if my logic is wrong. I'm...
0
2244
by: UncleRic | last post by:
Environment: Mac OS X (10.4.10) on MacBook Pro I'm a Perl Neophyte. I've downloaded the XML::Parser module and am attempting to install it in my working directory (referenced via PERL5LIB env): PERL5LIB=/Users/Ric/Library/Perl/ ls XML-Parser-2.34/ XML-Parser-2.34.tar
1
3268
by: runningsnake24 | last post by:
We are writing a program to check that a filled in Sudoku puzzle is solved correctly. We are required to use the Iterator and Iterable interfaces. The program uses a Cell class to represent each individual cell of a puzzle, and uses a 2D array to represent the entire puzzle. The next method in our class that implements Iterator must return a Cell object array that stores the current row, column and box that we are checking. I have figured...
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.