Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Servlets
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830
this week in the
Programmer Certification
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Servlets
Read file X lines
Carsten Rasmussen
Ranch Hand
Posts: 65
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is how i read my data.txt file.
String filename = request.getRealPath("/") + "/data.txt"; ServletOutputStream out = response.getOutputStream(); final int responseContentLength=7600; InputStream in = new FileInputStream(filename); byte[] bytes = new byte[responseContentLength]; int bytesRead; while ((bytesRead = in.read(bytes)) != -1) { out.write(bytes, 0, bytesRead); } in.close(); out.close();
I would like to read in bytes still, but is there a way to read maybe only 40 lines of the file in bytes.
My head hurts on this one so please help.
Ramkumar Subburaj
Ranch Hand
Posts: 83
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
try this one
FileReader fr = new FileReader("fileName.txt"); BufferedReader br = new BufferedReader(fr); String s; int lineCount = 1; while((s = br.readLine()) != null && lineCount <= 40) { System.out.println(s); lineCount ++; } fr.close();
SCJP 1.5, SCWCD 1.4.
Hanging between Web Services and EJB
Friends help you move. Good friends help you move bodies. This tiny ad will help:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to Actually UpLoad ?
Error calling Servlet from java file, while Servlet downloading file from website
EOFException keeps occuring after db read in
Streaming out data using ServletOutputStream
file transfer over TCP problem
More...