`

Easiest way to read write files in java 8

 
阅读更多
Path path = Paths.get(getClass().getClassLoader()
      .getResource("fileTest.txt").toURI()); //relative to the class

String content = new String(Files.readAllBytes(path));
try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
                stream.forEach(System.out::println);
            }


String text = "Text to save to file";
Files.write(Paths.get("./fileName.txt"), text.getBytes());

 

    public static String read(String fileName) throws IOException {
        InputStream resourceAsStream = FileUtility.class.getClassLoader().getResourceAsStream(fileName); // the filename is relative to the classpath root
        try (BufferedReader buffer = new BufferedReader(new InputStreamReader(resourceAsStream))) {
            return buffer.lines().collect(Collectors.joining("\n"));
        }
    }

 

 

分享到:
评论

相关推荐

    Django restful web services the easiest way to build python

    ### Django RESTful Web Services: The Easiest Way to Build Python #### 一、概述与背景 本书主要聚焦于如何利用Python及其最受欢迎的Web框架Django来构建RESTful Web服务。随着互联网技术的发展,RESTful Web...

    The easiest way to get started with PostgreSQL on the Mac.zip

    "The easiest way to get started with PostgreSQL on the Mac.zip" 提供了一个简洁的解决方案,旨在帮助Mac用户轻松入门。 压缩包中的文件"PostgresApp-master"是一个特别为Mac设计的PostgreSQL应用,它将数据库...

    The Kerbal Players Guide The Easiest Way to Launch a Space Program

    In this book, five KSP nerds—including an astrophysicist—teach you everything you need to know to get a nation of tiny green people into space. KSP is incredibly realistic. When running your space ...

    Learn Java Programming the easy

    This book provides the easiest way to learn Java Programming. It features concepts of Java Programming with simple examples. All difficult concepts are handled with simple and easy to understand ...

    2D Platformer 2016 Easiest Way to make a 2D Game v1.0.rar

    Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity优质资源Unity...

    The_easiest_way_to_use_R_package_

    The_easiest_way_to_use_R_package_bookdown_for__wri_bookdownplus

    Omoguru - The Easiest Way to Read-crx插件

    语言:English (United States) 对于有障碍,阅读,焦点和注意力困难,Omoguru发出清晰可理解的文字。 ------**我们想改善延期,您可以帮助我们。继续支持,让我们了解您的经验和建议。如果您喜欢延期,请向我们留下...

    <>

    Blockchain Easiest Ultimate Guide To Understand Blockchain By Jared Norton Copyright 2016 Jared Norton - All rights reserved. Excerpt From: Jared Norton. “Blockchain: Easiest Ultimate Guide To ...

    how-to-make-a-wheel-of-fortune-in-unity-the-easiest-way-master

    本教程将基于提供的"how-to-make-a-wheel-of-fortune-in-unity-the-easiest-way-master"项目,帮助你了解如何通过Unity实现这一功能。该压缩包中包含必要的美术资源和源码,便于你跟随教程进行学习。 首先,我们...

    MLPickerScrollView:The easiest way to use Picker ScrollView for iOS 横向滚动选择器

    MLPickerScrollViewIntroduction:The easiest way to use PickerScrollView这是一个对横向滚动选择器的自定义UI控件,只要几行代码就可以集成类似横向滚动中间放大的效果并且选中的功能。Presentation:模拟场景&lt;...

    Programming in Python 3 Second Edition

    Python is probably the easiest-to-learn and nicest-to-use programming language in widespread use. Python code is clear to read and write, and it is concise without being cryptic. Python is a very ...

    Advanced PDF Generator 2.0.0.0 Full Source

    Advanced PDF Generator gives you an opportunity to create PDF documents with your applications written on Delphi or C++ Builder in the most simple and easiest way. There is no need to know PDF ...

    开源FreeRTOS V10.1.0 最新版本

    The easiest way to use FreeRTOS is to start with one of the pre-configured demo application projects (found in the FreeRTOS/Demo directory). That way you will have the correct FreeRTOS source files ...

    《PHP & MySQL: Novice to Ninja, 6th Edition》2017 英文原版 Kindle - mobi格式

    The easiest way to learn PHP PHP & MySQL: Novice to Ninja, 6th Edition is a hands-on guide to learning all the tools, principles, and techniques needed to build a professional web application using ...

    《PHP &amp; MySQL: Novice to Ninja, 6th Edition》- 2017 英文原版

    The easiest way to learn PHP PHP & MySQL: Novice to Ninja, 6th Edition is a hands-on guide to learning all the tools, principles, and techniques needed to build a professional web application using ...

    Android.Programming.The.Easy.Way

    The Fastest and Easiest Way for Beginners to Develop Android Apps What’s Stopping You From Making Your Own Android Apps? The mobile phone app market is worth more than $25 billion and is expected ...

    Wubi, the easiest way to Linux!-开源

    Wubi是Windows用户的官方受支持的Ubuntu安装程序,只需单击即可将您带入Linux世界。 该网站已移至http://www.ubuntu.com/desktop/get-ubuntu/windows-installer,您可以在其中找到最新版本。

    PostgreSQL 11 Server Side Programming Quick Start Guide 1st Edition

    PostgreSQL is a rock-solid, scalable, and ...You will also learn how to produce extensions, the easiest way to package your programs for easy and solid deployment on different PostgreSQL installations.

Global site tag (gtag.js) - Google Analytics