Jump to content

How to read and write files

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
10 replies to this topic

#1
Adriann

Adriann

    Newbie

  • Members
  • Pip
  • 6 posts
I'm not sure how to read files and use the file lines in some other function of a program. For example, right now I'm trying to read a file of char's and then assign those each item into an array so I can access them later. If you could help, let me know!

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What is your code? It could be something simple.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
Reading, Writing, and Creating Files (The Java™ Tutorials > Essential Classes > Basic I/O)

show us some code if you want more detailed help.

#4
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
Maybe you can learn from this example.

it's pretty useless method, but you can edit it in any way you need.
public void readFile(String file) throws IOException{
		
		
	FileReader input = null;
	BufferedReader bufRead;
	String line;
	    
	input = new FileReader(file);
		
        bufRead = new BufferedReader(input);
        line="";   
              
        while(line != null){        
        	line = bufRead.readLine();		
		System.out.println(line); // prints the line
        }        
        bufRead.close();
}


#5
Adriann

Adriann

    Newbie

  • Members
  • Pip
  • 6 posts
that's all I needed to see. thanks!

#6
kiddies

kiddies

    Programmer

  • Members
  • PipPipPipPip
  • 130 posts
nice script....

#7
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

kiddies said:

nice script....

You could call it a script...
Posted Image

#8
Chinmoy

Chinmoy

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 392 posts
its' not a script.

God is real... unless declared an integer

my blog :: http://techarraz.com/


#9
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

Chinmoy said:

its' not a script.

You could not that you should call it a script
Posted Image

#10
mr_skyflakes21

mr_skyflakes21

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts
Let's just call it Code Snippet

#11
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

mr_skyflakes21 said:

Let's just call it Code Snippet

If you says so why not.
Posted Image