Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

88 users online



[JAVA] File handling

[JAVA] File handling

Currently viewing this thread: 1 (0 members and 1 guests)


IceCube

IceCube

Neverside Newbie
Status: Offline!

[JAVA] File handling

how do you open / read / write to a file in java?

___________________

waveartists.com - design shop
devnet.waveartists.comDesign & Programming community

Current Projects: ChaosOps mod (HalfLife2)

Zwitterion

Zwitterion

Status: Offline!

Not completely sure, but wouldn't it be somewhat the same as inputting it to a variable? I've been juggling C++ and java around for school, so not exactly sure of the syntax but something using an input operator '>'?

IceCube

IceCube

Neverside Newbie
Status: Offline!

inputStream?

___________________

waveartists.com - design shop
devnet.waveartists.comDesign & Programming community

Current Projects: ChaosOps mod (HalfLife2)

The_One1

The_One1

Status: Offline!

I Know i know!!

ok here is the code for writing to a file:

FileOutputStream fileHandle;
PrintWriter outputFile;

fileHandle = new FileOutputStream ("TopTen.txt");
outputFile = new PrintWriter(fileHandle);

and then after you declare this you can use
outputFile.print("whatever you want");
-OR-
outputFile.println("----");

if you just put in the name of the file like I did, it will go to the directory where your .java file is! if you want to go to another directory, you put the full path in there, ex. ("C:\\file.txt") you need 2 slashes because java takes the \ as a special character so \\ would be considered 1 \!

Reading from file:

FileReader File1;//creates a file input object
BufferedReader fileReader;//creates a buffered reader object
File1 = new FileReader("TopTen.txt");
fileReader = new BufferedReader (File1);

and then you use fileReader.readLine();
ex. temp = fileReader.readLine();

that takes input as a String, so you would have to use parseInt to go to Integer and so on!

IceCube

IceCube

Neverside Newbie
Status: Offline!

thanx

___________________

waveartists.com - design shop
devnet.waveartists.comDesign & Programming community

Current Projects: ChaosOps mod (HalfLife2)

IceCube

IceCube

Neverside Newbie
Status: Offline!

btw... does java have an explode function or something that lets me open a delimited string..

and line searching--- how do i do that?

___________________

waveartists.com - design shop
devnet.waveartists.comDesign & Programming community

Current Projects: ChaosOps mod (HalfLife2)

IceCube

IceCube

Neverside Newbie
Status: Offline!

btw... the code you supplied does only partually work... it creates a file but it does not fill the file with the output i issue

___________________

waveartists.com - design shop
devnet.waveartists.comDesign & Programming community

Current Projects: ChaosOps mod (HalfLife2)

IceCube

IceCube

Neverside Newbie
Status: Offline!

sorry... found it all out...

youll have to issue the close method to execute the writing

___________________

waveartists.com - design shop
devnet.waveartists.comDesign & Programming community

Current Projects: ChaosOps mod (HalfLife2)

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0073 seconds.