In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to write data in a specified format to a file with Scala". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to write data in a specified format to a file using Scala.
Create a new FileOps object:
Package com.ruozedata.day3
Import java.io. {File,PrintWriter}
Import java.text.SimpleDateFormat
Import java.util. {Calendar, Date}
/ / import scala.io.Source
Object FileOps {
Def main (args: Array [String]): Unit = {
/ / File reading
/ / val file = Source.fromFile ("D:\ software\\ data\\ scalaIO.txt")
/ / file.foreach (print)
/ / file.close () getTracffic ()
/ * *
* File format:
* domain tracffic time
* www.ruozedata.com64447 [2018-07-17 07:39:57]
* www.ruozedata.com13781 [2018-07-11 06:52:41]
, /
/ / File write
/ / load file D:\ software\ data\ ScalaWriter.txt will be created if not
Val writer = new PrintWriter (new File ("D:\\ software\\ data\\ ScalaWriter.txt")
Writer.flush (); / / clear the file contents
/ / enter the title field: domain tracffic time
/ / writer.println ("domain\ ttracffic\ ttime")
/ / define an array of URLs
Val arr = Array ("www.ruozedata.com", "www.zhibo8.com", "www.dongqiudi.com")
/ / defines a 26-letter array for randomly writing values (not numbers) to the tracffic field
Val arr2 = Array ("a", "b", "c", "d", "e", "f", "g", "h", "I", "j", "k", "l", "m", "n", "o", "p", "Q", "r", "s", "t", "u", "v", "w", "x", "y", "z")
/ / define a collection of numbers
Val arr3 = (10000 to 99999) .toArray
/ / variable used to receive tracic value
Var ele = ""
For (I)
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.