In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the JAVA language input and output stream sample code, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Public class IOStreamDemo {
Public void samples () throws IOException {
/ / 1. This is reading a line of data from the keyboard and returning a string.
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in))
System.out.print ("Enter a line:")
System.out.println (stdin.readLine ())
/ / 2. This is to read the data line by line from the file
BufferedReader in = new BufferedReader (new FileReader ("IOStreamDemo.java"))
String s, S2 = new String ()
While ((s = in.readLine ())! = null)
S2 + = s + ""
In.close ()
/ / 3. This is to read bytes one by one from a string
StringReader in1 = new StringReader (S2)
Int c
While ((c = in1.read ())! =-1)
System.out.print ((char) c)
/ / 4. This is to write a string to the file
Try {
BufferedReader in2 = new BufferedReader (new StringReader (S2))
PrintWriter out1 = new PrintWriter (new BufferedWriter (new FileWriter ("IODemo.out")
Int lineCount = 1
While ((s = in2.readLine ())! = null)
Out1.println (lineCount++ + ":" + s)
Out1.close ()
} catch (EOFException e) {
System.err.println ("End of stream")
}
}
}
Thank you for reading this article carefully. I hope the article "sample Code of JAVA language input and output Stream" shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.