In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to read local binaries into the String string, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
Note: this utility class can only read local files.
Import java.io.*;/** * File manipulation tool Class * * @ author edison_kwok * / public class FileUtils {/ * Local File renaming * * @ param file * @ param newName * / public static void rename (File file, String newName) {if (file.exists ()) {String absolutePath = file.getAbsolutePath () String path = absolutePath.substring (0, absolutePath.lastIndexOf ("\") + 1); file.renameTo (new File (path + newName)) }} / * function: Java reads the contents of the txt file * step: 1: get the file handle * 2: get the file handle as an input byte stream, and you need to read the input stream * 3: after reading the input stream, you need to read the output of the generated byte stream * 4: one line. Readline (). * Note: the exception needs to be considered * * @ param filePath * / public static String readFile (String filePath) {InputStreamReader read = null; BufferedReader bufferedReader = null; String lineTxt = null; try {String encoding = "UTF-8"; File file = new File (filePath) / / determine whether the file exists if (file.isFile () & & file.exists ()) {/ / considering the encoding format read = new InputStreamReader (new FileInputStream (file), encoding); bufferedReader = new BufferedReader (read); StringBuilder stringBuilder = new StringBuilder () While ((lineTxt = bufferedReader.readLine ())! = null) {stringBuilder.append (lineTxt);} return stringBuilder.toString ();} else {throw new RuntimeException ("the file does not exist") } catch (Exception e) {throw new RuntimeException (e.getMessage ());} finally {try {if (bufferedReader! = null) {bufferedReader.close ();} if (read! = null) {read.close () }} catch (IOException e) {e.printStackTrace ();}} / * the output stream exports the local file * * @ param is * @ param os * @ throws Exception * / public static void fileUpload (InputStream is, OutputStream os) throws Exception {byte [] b = new byte [2048] Int length = 0; while (true) {length = is.read (b); if (length < 0) break; os.write (b, 0, length);} is.close (); os.close ();}} the above is how to read local binaries into the String string. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.