-
Notifications
You must be signed in to change notification settings - Fork 52
io microsphere nio file Files
Type: Class | Module: microsphere-java-core | Package: io.microsphere.nio.file | Since: 1.0.0
Source:
microsphere-java-core/src/main/java/io/microsphere/nio/file/Files.java
The utilties class of File based on NIO
public abstract class Files implements UtilsAuthor: Mercy
-
Introduced in:
1.0.0 -
Current Project Version:
0.3.18-SNAPSHOT
This component is tested and compatible with the following Java versions:
| Java Version | Status |
|---|---|
| Java 8 | ✅ Compatible |
| Java 11 | ✅ Compatible |
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |
File file = new File("/example.txt");
try {
String[] lines = Files.readLines(file);
for (String line : lines) {
System.out.println(line);
}
} catch(IOException e) {
// Handle the exception
}File file = new File("/example.txt");
Charset charset = java.nio.charset.StandardCharsets.UTF_8;
try {
String[] lines = Files.readLines(file, charset);
for (String line : lines) {
System.out.println(line);
}
} catch(IOException e) {
// Handle the exception
}Path filePath = Paths.get("/example.txt");
try {
String[] lines = Files.readLines(filePath);
for (String line : lines) {
System.out.println(line);
}
} catch(IOException e) {
// Handle the exception
}Path filePath = Paths.get("/example.txt");
Charset charset = java.nio.charset.StandardCharsets.UTF_8;
try {
String[] lines = Files.readLines(filePath, charset);
for (String line : lines) {
System.out.println(line);
}
} catch(IOException e) {
// Handle the exception
}Add the following dependency to your pom.xml:
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-java-core</artifactId>
<version>${microsphere-java.version}</version>
</dependency>Tip: Use the BOM (
microsphere-java-dependencies) for consistent version management. See the Getting Started guide.
import io.microsphere.nio.file.Files;| Method | Description |
|---|---|
readLines |
Reads all lines from the given file and returns them as an array of strings, |
readLines |
Reads all lines from the given file and returns them as an array of strings, |
readLines |
Reads all lines from the given file path and returns them as an array of strings, |
readLines |
Reads all lines from the given file path and returns them as an array of strings, |
public static String[] readLines(File file)Reads all lines from the given file and returns them as an array of strings,
using the default Charset for decoding.
This method reads the entire content of the file, converts it to a string using the default charset, and then splits the string into lines based on the system line separator. The file input stream is automatically closed after this operation.
`File file = new File("/example.txt");
try {
String[] lines = Files.readLines(file);
for (String line : lines) {
System.out.println(line);
`
} catch(IOException e) {
// Handle the exception
}
}
public static String[] readLines(File file, Charset charset)Reads all lines from the given file and returns them as an array of strings,
using the specified Charset for decoding.
This method reads the entire content of the file, converts it to a string using the provided charset, and then splits the string into lines based on the system line separator. The file input stream is automatically closed after this operation.
`File file = new File("/example.txt");
Charset charset = java.nio.charset.StandardCharsets.UTF_8;
try {
String[] lines = Files.readLines(file, charset);
for (String line : lines) {
System.out.println(line);
`
} catch(IOException e) {
// Handle the exception
}
}
public static String[] readLines(Path filePath)Reads all lines from the given file path and returns them as an array of strings,
using the default Charset for decoding.
This method reads the entire content of the file, converts it to a string using the default charset, and then splits the string into lines based on the system line separator. The file input stream is automatically closed after this operation.
`Path filePath = Paths.get("/example.txt");
try {
String[] lines = Files.readLines(filePath);
for (String line : lines) {
System.out.println(line);
`
} catch(IOException e) {
// Handle the exception
}
}
public static String[] readLines(Path filePath, Charset charset)Reads all lines from the given file path and returns them as an array of strings,
using the specified Charset for decoding.
This method reads the entire content of the file, converts it to a string using the provided charset, and then splits the string into lines based on the system line separator. The file input stream is automatically closed after this operation.
`Path filePath = Paths.get("/example.txt");
Charset charset = java.nio.charset.StandardCharsets.UTF_8;
try {
String[] lines = Files.readLines(filePath, charset);
for (String line : lines) {
System.out.println(line);
`
} catch(IOException e) {
// Handle the exception
}
}
Path
This documentation was auto-generated from the source code of microsphere-java.
annotation-processor
- ConfigurationPropertyAnnotationProcessor
- ConfigurationPropertyJSONElementVisitor
- FilerProcessor
- ResourceProcessor
annotation-test
java-annotations
java-core
- ACLLoggerFactory
- AbstractArtifactResourceResolver
- AbstractConverter
- AbstractDeque
- AbstractEventDispatcher
- AbstractLogger
- AbstractSerializer
- AbstractURLClassPathHandle
- AccessibleObjectUtils
- AdditionalMetadataResourceConfigurationPropertyLoader
- AnnotationUtils
- ArchiveFileArtifactResourceResolver
- ArrayEnumeration
- ArrayStack
- ArrayUtils
- Artifact
- ArtifactDetector
- ArtifactResourceResolver
- Assert
- BannedArtifactClassLoadingExecutor
- BaseUtils
- BeanMetadata
- BeanProperty
- BeanUtils
- BooleanSerializer
- ByteArrayToObjectConverter
- ByteSerializer
- CharSequenceComparator
- CharSequenceUtils
- CharacterSerializer
- CharsetUtils
- ClassDataRepository
- ClassDefinition
- ClassFileJarEntryFilter
- ClassFilter
- ClassLoaderUtils
- ClassPathResourceConfigurationPropertyLoader
- ClassPathUtils
- ClassUtils
- ClassicProcessIdResolver
- ClassicURLClassPathHandle
- CollectionUtils
- Compatible
- CompositeSubProtocolURLConnectionFactory
- CompositeURLStreamHandlerFactory
- ConditionalEventListener
- ConfigurationProperty
- ConfigurationPropertyGenerator
- ConfigurationPropertyLoader
- ConfigurationPropertyReader
- Configurer
- ConsoleURLConnection
- ConstantPoolUtils
- Constants
- ConstructorDefinition
- ConstructorUtils
- Converter
- Converters
- CustomizedThreadFactory
- DefaultConfigurationPropertyGenerator
- DefaultConfigurationPropertyReader
- DefaultDeserializer
- DefaultEntry
- DefaultSerializer
- DelegatingBlockingQueue
- DelegatingDeque
- DelegatingIterator
- DelegatingQueue
- DelegatingScheduledExecutorService
- DelegatingURLConnection
- DelegatingURLStreamHandlerFactory
- DelegatingWrapper
- Deprecation
- Deserializer
- Deserializers
- DirectEventDispatcher
- DirectoryFileFilter
- DoubleSerializer
- EmptyDeque
- EmptyIterable
- EmptyIterator
- EnumSerializer
- EnumerationIteratorAdapter
- EnumerationUtils
- Event
- EventDispatcher
- EventListener
- ExceptionUtils
- ExecutableDefinition
- ExecutableUtils
- ExecutorUtils
- ExtendableProtocolURLStreamHandler
- FastByteArrayInputStream
- FastByteArrayOutputStream
- FieldDefinition
- FieldUtils
- FileChangedEvent
- FileChangedListener
- FileConstants
- FileExtensionFilter
- FileUtils
- FileWatchService
- Files
- Filter
- FilterOperator
- FilterUtils
- FloatSerializer
- FormatUtils
- Functional
- GenericEvent
- GenericEventListener
- Handler
- Handler
- HierarchicalClassComparator
- IOFileFilter
- IOUtils
- ImmutableEntry
- IntegerSerializer
- IterableAdapter
- IterableUtils
- Iterators
- JDKLoggerFactory
- JSON
- JSONArray
- JSONException
- JSONObject
- JSONStringer
- JSONTokener
- JSONUtils
- JarEntryFilter
- JarUtils
- JavaType
- JmxUtils
- LambdaUtils
- ListUtils
- Listenable
- Lists
- Logger
- LoggerFactory
- LoggerUtils
- LoggingFileChangedListener
- LongSerializer
- MBeanAttribute
- MBeanAttributeInfoBuilder
- MBeanConstructorInfoBuilder
- MBeanDescribableBuilder
- MBeanExecutableInfoBuilder
- MBeanFeatureInfoBuilder
- MBeanInfoBuilder
- MBeanNotificationInfoBuilder
- MBeanOperationInfoBuilder
- MBeanParameterInfoBuilder
- ManagementUtils
- ManifestArtifactResourceResolver
- MapToPropertiesConverter
- MapUtils
- Maps
- MavenArtifact
- MavenArtifactResourceResolver
- MemberDefinition
- MemberUtils
- MetadataResourceConfigurationPropertyLoader
- MethodDefinition
- MethodHandleUtils
- MethodHandlesLookupUtils
- MethodUtils
- ModernProcessIdResolver
- ModernURLClassPathHandle
- Modifier
- MultiValueConverter
- MultipleType
- MutableInteger
- MutableURLStreamHandlerFactory
- NameFileFilter
- NoOpLogger
- NoOpLoggerFactory
- NoOpURLClassPathHandle
- NumberToByteConverter
- NumberToCharacterConverter
- NumberToDoubleConverter
- NumberToFloatConverter
- NumberToIntegerConverter
- NumberToLongConverter
- NumberToShortConverter
- NumberUtils
- ObjectToBooleanConverter
- ObjectToByteArrayConverter
- ObjectToByteConverter
- ObjectToCharacterConverter
- ObjectToDoubleConverter
- ObjectToFloatConverter
- ObjectToIntegerConverter
- ObjectToLongConverter
- ObjectToOptionalConverter
- ObjectToShortConverter
- ObjectToStringConverter
- ObjectUtils
- PackageNameClassFilter
- PackageNameClassNameFilter
- ParallelEventDispatcher
- ParameterizedTypeImpl
- PathConstants
- Predicates
- Prioritized
- PriorityComparator
- ProcessExecutor
- ProcessIdResolver
- ProcessManager
- PropertiesToStringConverter
- PropertiesUtils
- PropertyConstants
- PropertyResourceBundleControl
- PropertyResourceBundleUtils
- ProtocolConstants
- ProxyUtils
- QueueUtils
- ReadOnlyIterator
- ReflectionUtils
- ReflectiveConfigurationPropertyGenerator
- ReflectiveDefinition
- ResourceConstants
- ReversedDeque
- Scanner
- SecurityUtils
- SeparatorConstants
- Serializer
- Serializers
- ServiceLoaderURLStreamHandlerFactory
- ServiceLoaderUtils
- ServiceLoadingURLClassPathHandle
- SetUtils
- Sets
- Sfl4jLoggerFactory
- ShortSerializer
- ShutdownHookCallbacksThread
- ShutdownHookUtils
- SimpleClassScanner
- SimpleFileScanner
- SimpleJarEntryScanner
- SingletonDeque
- SingletonEnumeration
- SingletonIterator
- SizeUtils
- StackTraceUtils
- StandardFileWatchService
- StandardURLStreamHandlerFactory
- StopWatch
- StreamArtifactResourceResolver
- Streams
- StringBuilderWriter
- StringConverter
- StringDeserializer
- StringSerializer
- StringToArrayConverter
- StringToBlockingDequeConverter
- StringToBlockingQueueConverter
- StringToBooleanConverter
- StringToByteConverter
- StringToCharArrayConverter
- StringToCharacterConverter
- StringToClassConverter
- StringToCollectionConverter
- StringToDequeConverter
- StringToDoubleConverter
- StringToDurationConverter
- StringToFloatConverter
- StringToInputStreamConverter
- StringToIntegerConverter
- StringToIterableConverter
- StringToListConverter
- StringToLongConverter
- StringToMultiValueConverter
- StringToNavigableSetConverter
- StringToQueueConverter
- StringToSetConverter
- StringToShortConverter
- StringToSortedSetConverter
- StringToStringConverter
- StringToTransferQueueConverter
- StringUtils
- SubProtocolURLConnectionFactory
- SymbolConstants
- SystemUtils
- ThrowableAction
- ThrowableBiConsumer
- ThrowableBiFunction
- ThrowableConsumer
- ThrowableFunction
- ThrowableSupplier
- ThrowableUtils
- TrueClassFilter
- TrueFileFilter
- TypeArgument
- TypeFinder
- TypeUtils
- URLClassPathHandle
- URLUtils
- UnmodifiableDeque
- UnmodifiableIterator
- UnmodifiableQueue
- UnsafeUtils
- Utils
- ValueHolder
- Version
- VersionUtils
- VirtualMachineProcessIdResolver
- Wrapper
- WrapperProcessor
java-test
- Ancestor
- ArrayTypeModel
- CollectionTypeModel
- Color
- ConfigurationPropertyModel
- DefaultTestService
- GenericTestService
- MapTypeModel
- Model
- Parent
- PrimitiveTypeModel
- SimpleTypeModel
- StringArrayList
- TestAnnotation
- TestService
- TestServiceImpl
jdk-tools
lang-model